1+ import builtins
2+ import contextlib
13from logging import getLogger
2- from os import path as ospath , listdir
4+ from os import listdir
5+ from os import path as ospath
36from re import search as re_search
4- from secrets import token_urlsafe
5- from yt_dlp import YoutubeDL , DownloadError
67
8+ from yt_dlp import DownloadError , YoutubeDL
79
8- from .... import task_dict_lock , task_dict
9- from ...ext_utils .bot_utils import sync_to_async , async_to_sync
10- from ...ext_utils .task_manager import check_running_tasks , stop_duplicate_check
11- from ...mirror_leech_utils .status_utils .queue_status import QueueStatus
12- from ...telegram_helper .message_utils import send_status_message
13- from ..status_utils .yt_dlp_status import YtDlpStatus
10+ from bot import task_dict , task_dict_lock
11+ from bot .helper .ext_utils .bot_utils import async_to_sync , sync_to_async
12+ from bot .helper .ext_utils .task_manager import (
13+ check_running_tasks ,
14+ stop_duplicate_check ,
15+ )
16+ from bot .helper .mirror_leech_utils .status_utils .queue_status import QueueStatus
17+ from bot .helper .mirror_leech_utils .status_utils .yt_dlp_status import YtDlpStatus
18+ from bot .helper .telegram_helper .message_utils import send_status_message
1419
1520LOGGER = getLogger (__name__ )
1621
@@ -22,14 +27,14 @@ def __init__(self, obj, listener):
2227
2328 def debug (self , msg ):
2429 # Hack to fix changing extension
25- if not self ._obj .is_playlist :
26- if match := re_search (
27- r".Merger..Merging formats into ..(.*?). $" , msg
28- ) or re_search ( r".ExtractAudio..Destination..(.*?)$" , msg ):
29- LOGGER .info (msg )
30- newname = match .group (1 )
31- newname = newname .rsplit ("/" , 1 )[- 1 ]
32- self ._listener .name = newname
30+ if not self ._obj .is_playlist and (
31+ match := re_search (r".Merger..Merging formats into..(.*?).$" , msg )
32+ or re_search ( r".ExtractAudio..Destination ..(.*?)$" , msg )
33+ ):
34+ LOGGER .info (msg )
35+ newname = match .group (1 )
36+ newname = newname .rsplit ("/" , 1 )[- 1 ]
37+ self ._listener .name = newname
3338
3439 @staticmethod
3540 def warning (msg ):
@@ -116,14 +121,14 @@ def _on_download_progress(self, d):
116121 self ._listener .size = d ["total_bytes_estimate" ] or 0
117122 self ._downloaded_bytes = d ["downloaded_bytes" ] or 0
118123 self ._eta = d .get ("eta" , "-" ) or "-"
119- try :
124+ with contextlib . suppress ( builtins . BaseException ) :
120125 self ._progress = (self ._downloaded_bytes / self ._listener .size ) * 100
121- except :
122- pass
123126
124127 async def _on_download_start (self , from_queue = False ):
125128 async with task_dict_lock :
126- task_dict [self ._listener .mid ] = YtDlpStatus (self ._listener , self , self ._gid )
129+ task_dict [self ._listener .mid ] = YtDlpStatus (
130+ self ._listener , self , self ._gid
131+ )
127132 if not from_queue :
128133 await self ._listener .on_download_start ()
129134 if self ._listener .multi <= 1 :
@@ -147,7 +152,7 @@ def _extract_meta_data(self):
147152 for entry in result ["entries" ]:
148153 if not entry :
149154 continue
150- elif "filesize_approx" in entry :
155+ if "filesize_approx" in entry :
151156 self ._listener .size += entry .get ("filesize_approx" , 0 ) or 0
152157 elif "filesize" in entry :
153158 self ._listener .size += entry .get ("filesize" , 0 ) or 0
@@ -163,10 +168,13 @@ def _extract_meta_data(self):
163168 realName = ydl .prepare_filename (result , outtmpl = outtmpl_ )
164169 ext = ospath .splitext (realName )[- 1 ]
165170 self ._listener .name = (
166- f"{ self ._listener .name } { ext } " if self ._listener .name else realName
171+ f"{ self ._listener .name } { ext } "
172+ if self ._listener .name
173+ else realName
167174 )
168175 if not self ._ext :
169176 self ._ext = ext
177+ return None
170178
171179 def _download (self , path ):
172180 try :
@@ -356,4 +364,4 @@ def _set_options(self, options):
356364 else :
357365 if key == "writethumbnail" and value is True :
358366 self .keep_thumb = True
359- self .opts [key ] = value
367+ self .opts [key ] = value
0 commit comments