Skip to content

Commit 1a2e5f6

Browse files
committed
fix yt-dlp original thumnail
Signed-off-by: anasty17 <e.anastayyar@gmail.com>
1 parent f70f3ae commit 1a2e5f6

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

bot/helper/ext_utils/files_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def get_mime_type(file_path):
209209

210210
async def remove_excluded_files(fpath, ee):
211211
for root, _, files in await sync_to_async(walk, fpath):
212+
if root.strip().endswith("/yt-dlp-thumb"):
213+
continue
212214
for f in files:
213215
if f.strip().lower().endswith(tuple(ee)):
214216
await remove(ospath.join(root, f))

bot/helper/mirror_leech_utils/download_utils/yt_dlp_download.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from secrets import token_urlsafe
55
from yt_dlp import YoutubeDL, DownloadError
66

7+
78
from .... import task_dict_lock, task_dict
89
from ...ext_utils.bot_utils import sync_to_async, async_to_sync
910
from ...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

bot/helper/mirror_leech_utils/telegram_uploader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ async def _upload_file(self, cap_mono, file, o_path, force_document=False):
342342
thumb_path = f"{self._path}/yt-dlp-thumb/{file_name}.jpg"
343343
if await aiopath.isfile(thumb_path):
344344
thumb = thumb_path
345+
elif await aiopath.isfile(thumb_path.replace("/yt-dlp-thumb", "")):
346+
thumb = thumb_path.replace("/yt-dlp-thumb", "")
345347
elif is_audio and not is_video:
346348
thumb = await get_audio_thumbnail(self._up_path)
347349

0 commit comments

Comments
 (0)