44from secrets import token_urlsafe
55from yt_dlp import YoutubeDL , DownloadError
66
7+
78from .... import task_dict_lock , task_dict
89from ...ext_utils .bot_utils import sync_to_async , async_to_sync
910from ...ext_utils .task_manager import check_running_tasks , stop_duplicate_check
@@ -51,6 +52,7 @@ def __init__(self, listener):
5152 self ._gid = ""
5253 self ._ext = ""
5354 self .is_playlist = False
55+ self .keep_thumb = False
5456 self .opts = {
5557 "progress_hooks" : [self ._on_download_progress ],
5658 "logger" : MyLogger (self , self ._listener ),
@@ -225,6 +227,9 @@ async def add_download(self, path, qual, playlist, options):
225227 else :
226228 self ._ext = f".{ audio_format } "
227229
230+ if not self ._listener .is_leech or self ._listener .thumbnail_layout :
231+ self .opts ["writethumbnail" ] = False
232+
228233 if options :
229234 self ._set_options (options )
230235
@@ -244,15 +249,16 @@ async def add_download(self, path, qual, playlist, options):
244249 )
245250 base_name = ospath .splitext (self ._listener .name )[0 ]
246251
252+ start_path = path if self .keep_thumb else f"{ path } /yt-dlp-thumb"
247253 if self .is_playlist :
248254 self .opts ["outtmpl" ] = {
249255 "default" : f"{ path } /{ self ._listener .name } /%(title,fulltitle,alt_title)s%(season_number& |)s%(season_number&S|)s%(season_number|)02d%(episode_number&E|)s%(episode_number|)02d%(height& |)s%(height|)s%(height&p|)s%(fps|)s%(fps&fps|)s%(tbr& |)s%(tbr|)d.%(ext)s" ,
250- "thumbnail" : f"{ path } /yt-dlp-thumb /%(title,fulltitle,alt_title)s%(season_number& |)s%(season_number&S|)s%(season_number|)02d%(episode_number&E|)s%(episode_number|)02d%(height& |)s%(height|)s%(height&p|)s%(fps|)s%(fps&fps|)s%(tbr& |)s%(tbr|)d.%(ext)s" ,
256+ "thumbnail" : f"{ start_path } /%(title,fulltitle,alt_title)s%(season_number& |)s%(season_number&S|)s%(season_number|)02d%(episode_number&E|)s%(episode_number|)02d%(height& |)s%(height|)s%(height&p|)s%(fps|)s%(fps&fps|)s%(tbr& |)s%(tbr|)d.%(ext)s" ,
251257 }
252258 elif "download_ranges" in options :
253259 self .opts ["outtmpl" ] = {
254260 "default" : f"{ path } /{ base_name } /%(section_number|)s%(section_number&.|)s%(section_title|)s%(section_title&-|)s%(title,fulltitle,alt_title)s %(section_start)s to %(section_end)s.%(ext)s" ,
255- "thumbnail" : f"{ path } /yt-dlp-thumb /%(section_number|)s%(section_number&.|)s%(section_title|)s%(section_title&-|)s%(title,fulltitle,alt_title)s %(section_start)s to %(section_end)s.%(ext)s" ,
261+ "thumbnail" : f"{ start_path } /%(section_number|)s%(section_number&.|)s%(section_title|)s%(section_title&-|)s%(title,fulltitle,alt_title)s %(section_start)s to %(section_end)s.%(ext)s" ,
256262 }
257263 elif any (
258264 key in options
@@ -262,25 +268,26 @@ async def add_download(self, path, qual, playlist, options):
262268 "writeannotations" ,
263269 "writedesktoplink" ,
264270 "writewebloclink" ,
271+ "writelink" ,
265272 "writeurllink" ,
266273 "writesubtitles" ,
267- "writeautomaticsub " ,
274+ "write_all_thumbnails " ,
268275 ]
269276 ):
270277 self .opts ["outtmpl" ] = {
271278 "default" : f"{ path } /{ base_name } /{ self ._listener .name } " ,
272- "thumbnail" : f"{ path } /yt-dlp-thumb /{ base_name } .%(ext)s" ,
279+ "thumbnail" : f"{ start_path } /{ base_name } .%(ext)s" ,
273280 }
274281 else :
275282 self .opts ["outtmpl" ] = {
276283 "default" : f"{ path } /{ self ._listener .name } " ,
277- "thumbnail" : f"{ path } /yt-dlp-thumb /{ base_name } .%(ext)s" ,
284+ "thumbnail" : f"{ start_path } /{ base_name } .%(ext)s" ,
278285 }
279286
280287 if qual .startswith ("ba/b" ):
281288 self ._listener .name = f"{ base_name } { self ._ext } "
282289
283- if self ._listener . is_leech and not self . _listener . thumbnail_layout :
290+ if self .opts [ "writethumbnail" ] :
284291 self .opts ["postprocessors" ].append (
285292 {
286293 "format" : "jpg" ,
@@ -302,14 +309,10 @@ async def add_download(self, path, qual, playlist, options):
302309 ]:
303310 self .opts ["postprocessors" ].append (
304311 {
305- "already_have_thumbnail" : bool (
306- self ._listener .is_leech and not self ._listener .thumbnail_layout
307- ),
312+ "already_have_thumbnail" : self .opts ["writethumbnail" ],
308313 "key" : "EmbedThumbnail" ,
309314 }
310315 )
311- elif not self ._listener .is_leech :
312- self .opts ["writethumbnail" ] = False
313316
314317 msg , button = await stop_duplicate_check (self ._listener )
315318 if msg :
@@ -350,4 +353,6 @@ def _set_options(self, options):
350353 if isinstance (value , list ):
351354 self .opts [key ] = lambda info , ytdl : value
352355 else :
356+ if key == "writethumbnail" and value is True :
357+ self .keep_thumb = True
353358 self .opts [key ] = value
0 commit comments