From 910ecc422930bca14e2abe4986f5f92359e3cea8 Mon Sep 17 00:00:00 2001 From: bashonly <88596187+bashonly@users.noreply.github.com> Date: Wed, 27 Nov 2024 00:45:01 +0000 Subject: [PATCH] [ie/tiktok] Deprioritize animated thumbnails (#11645) Closes #11641 Authored by: bashonly --- yt_dlp/extractor/tiktok.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/yt_dlp/extractor/tiktok.py b/yt_dlp/extractor/tiktok.py index ba15f08b6d..9e53b34072 100644 --- a/yt_dlp/extractor/tiktok.py +++ b/yt_dlp/extractor/tiktok.py @@ -413,15 +413,6 @@ class TikTokBaseIE(InfoExtractor): for f in formats: self._set_cookie(urllib.parse.urlparse(f['url']).hostname, 'sid_tt', auth_cookie.value) - thumbnails = [] - for cover_id in ('cover', 'ai_dynamic_cover', 'animated_cover', 'ai_dynamic_cover_bak', - 'origin_cover', 'dynamic_cover'): - for cover_url in traverse_obj(video_info, (cover_id, 'url_list', ...)): - thumbnails.append({ - 'id': cover_id, - 'url': cover_url, - }) - stats_info = aweme_detail.get('statistics') or {} music_info = aweme_detail.get('music') or {} labels = traverse_obj(aweme_detail, ('hybrid_label', ..., 'text'), expected_type=str) @@ -467,7 +458,17 @@ class TikTokBaseIE(InfoExtractor): 'formats': formats, 'subtitles': self.extract_subtitles( aweme_detail, aweme_id, traverse_obj(author_info, 'uploader', 'uploader_id', 'channel_id')), - 'thumbnails': thumbnails, + 'thumbnails': [ + { + 'id': cover_id, + 'url': cover_url, + 'preference': -1 if cover_id in ('cover', 'origin_cover') else -2, + } + for cover_id in ( + 'cover', 'ai_dynamic_cover', 'animated_cover', + 'ai_dynamic_cover_bak', 'origin_cover', 'dynamic_cover') + for cover_url in traverse_obj(video_info, (cover_id, 'url_list', ...)) + ], 'duration': (traverse_obj(video_info, ( (None, 'download_addr'), 'duration', {int_or_none(scale=1000)}, any)) or traverse_obj(music_info, ('duration', {int_or_none}))), @@ -600,11 +601,15 @@ class TikTokBaseIE(InfoExtractor): 'repost_count': 'shareCount', 'comment_count': 'commentCount', }), expected_type=int_or_none), - 'thumbnails': traverse_obj(aweme_detail, ( - (None, 'video'), ('thumbnail', 'cover', 'dynamicCover', 'originCover'), { - 'url': ({url_or_none}, {self._proto_relative_url}), - }, - )), + 'thumbnails': [ + { + 'id': cover_id, + 'url': self._proto_relative_url(cover_url), + 'preference': -2 if cover_id == 'dynamicCover' else -1, + } + for cover_id in ('thumbnail', 'cover', 'dynamicCover', 'originCover') + for cover_url in traverse_obj(aweme_detail, ((None, 'video'), cover_id, {url_or_none})) + ], }