From deaaca0aff90ccc2610af580c14c4bd2bd79e520 Mon Sep 17 00:00:00 2001 From: MrDemocracy Date: Wed, 20 Nov 2024 17:00:40 +0100 Subject: [PATCH 1/4] [disney] Handle redirects and updating tests --- yt_dlp/extractor/disney.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/yt_dlp/extractor/disney.py b/yt_dlp/extractor/disney.py index a90f12389e..ab3871f3ee 100644 --- a/yt_dlp/extractor/disney.py +++ b/yt_dlp/extractor/disney.py @@ -7,6 +7,7 @@ join_nonempty, unified_strdate, update_url_query, + traverse_obj, ) @@ -22,6 +23,8 @@ class DisneyIE(InfoExtractor): 'title': 'Moana - Trailer', 'description': 'A fun adventure for the entire Family! Bring home Moana on Digital HD Feb 21 & Blu-ray March 7', 'upload_date': '20170112', + 'duration': 95, + 'thumbnail': 'https://lumiere-a.akamaihd.net/v1/images/545ed1857afee5a0ec239977_84a55142.jpeg?height=354®ion=0%2C144%2C1920%2C792&width=630', }, 'params': { # m3u8 download @@ -36,6 +39,8 @@ class DisneyIE(InfoExtractor): 'title': '"Intro" Featurette: Rogue One: A Star Wars Story', 'upload_date': '20170104', 'description': 'Go behind-the-scenes of Rogue One: A Star Wars Story in this featurette with Director Gareth Edwards and the cast of the film.', + 'duration': 122, + 'thumbnail': 'https://lumiere-a.akamaihd.net/v1/images/r1-featurette-11-17-yt_9b401d61.jpeg?height=354®ion=0%2C0%2C1920%2C1080&width=630', }, 'params': { # m3u8 download @@ -73,18 +78,21 @@ class DisneyIE(InfoExtractor): 'only_matching': True, }] + # https://www.starwars.com times out with the default user-agent + _USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0' + def _real_extract(self, url): domain, video_id, display_id = self._match_valid_url(url).groups() if not video_id: - webpage = self._download_webpage(url, display_id) + webpage = self._download_webpage(url, display_id, headers={'user-agent': self._USER_AGENT}) grill = re.sub(r'"\s*\+\s*"', '', self._search_regex( r'Grill\.burger\s*=\s*({.+})\s*:', webpage, 'grill data')) - page_data = next(s for s in self._parse_json(grill, display_id)['stack'] if s.get('type') == 'video') - video_data = page_data['data'][0] + video_data = next(traverse_obj(s, ('data', 0, 'video')) or traverse_obj(s, ('data', 0)) for s in self._parse_json(grill, + display_id)['stack'] if s.get('type') in ('video', 'flexcontenthero')) else: webpage = self._download_webpage( - f'http://{domain}/embed/{video_id}', video_id) + f'http://{domain}/embed/{video_id}', video_id, headers={'user-agent': self._USER_AGENT}) page_data = self._parse_json(self._search_regex( r'Disney\.EmbedVideo\s*=\s*({.+});', webpage, 'embed data'), video_id) @@ -101,6 +109,10 @@ def _real_extract(self, url): for flavor in video_data.get('flavors', []): flavor_format = flavor.get('format') flavor_url = flavor.get('url') + if '/emea-exit/' in flavor_url: + webpage = self._download_webpage(flavor_url, display_id, headers={'user-agent': self._USER_AGENT}, note=False) + flavor_url = self._search_regex(r'rel="canonical" href="([^"]+)', + webpage, 'redirect url') if not flavor_url or not re.match(r'https?://', flavor_url) or flavor_format == 'mp4_access': continue tbr = int_or_none(flavor.get('bitrate')) From 1525369833cb57a6b7041706b38bda4871e2ebce Mon Sep 17 00:00:00 2001 From: MrDemocracy Date: Wed, 20 Nov 2024 17:27:09 +0100 Subject: [PATCH 2/4] [disney] Add new test case and alternate upload_date extraction for other languages --- yt_dlp/extractor/disney.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/yt_dlp/extractor/disney.py b/yt_dlp/extractor/disney.py index ab3871f3ee..35dadd3c0f 100644 --- a/yt_dlp/extractor/disney.py +++ b/yt_dlp/extractor/disney.py @@ -76,6 +76,22 @@ class DisneyIE(InfoExtractor): }, { 'url': 'http://disneyjunior.disney.com/galactech-the-galactech-grab-galactech-an-admiral-rescue', 'only_matching': True, + }, { + # Grill.burger + 'url': 'http://kids.disney.co.jp/video/3178', + 'info_dict': { + 'id': '5e926e4097ecfebd6b4f2a72', + 'ext': 'mp4', + 'title': '本編第1話(ほんぺんだい1わ) マーベル アルティメット・スパイダーマン\u3000ウェブ・ウォーリアーズ', + 'upload_date': '20221018', + 'description': 'md5:7978279f5a9b79e350613b8e0a507c24', + 'duration': 1320, + 'thumbnail': 'https://lumiere-a.akamaihd.net/v1/images/26412_32232_31532_1_35441_12510_12540_12505_12523_12450_1e89505b.jpeg?region=0%2C0%2C1280%2C720', + }, + 'params': { + # m3u8 download + 'skip_download': True, + }, }] # https://www.starwars.com times out with the default user-agent @@ -166,7 +182,7 @@ def _real_extract(self, url): 'description': video_data.get('description') or video_data.get('short_desc'), 'thumbnail': video_data.get('thumb') or video_data.get('thumb_secure'), 'duration': int_or_none(video_data.get('duration_sec')), - 'upload_date': unified_strdate(video_data.get('publish_date')), + 'upload_date': unified_strdate(video_data.get('publish_date')) or re.sub(r'\D', '', video_data.get('content_date').split('T')[0]), 'formats': formats, 'subtitles': subtitles, } From 683c166daace08200e7e08daa9d87096b7b36e85 Mon Sep 17 00:00:00 2001 From: MrDemocracy Date: Wed, 20 Nov 2024 17:47:52 +0100 Subject: [PATCH 3/4] [disney] Avoid splitting NoneType --- yt_dlp/extractor/disney.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yt_dlp/extractor/disney.py b/yt_dlp/extractor/disney.py index 35dadd3c0f..0aa34568c1 100644 --- a/yt_dlp/extractor/disney.py +++ b/yt_dlp/extractor/disney.py @@ -5,9 +5,9 @@ determine_ext, int_or_none, join_nonempty, + traverse_obj, unified_strdate, update_url_query, - traverse_obj, ) @@ -105,7 +105,7 @@ def _real_extract(self, url): r'Grill\.burger\s*=\s*({.+})\s*:', webpage, 'grill data')) video_data = next(traverse_obj(s, ('data', 0, 'video')) or traverse_obj(s, ('data', 0)) for s in self._parse_json(grill, - display_id)['stack'] if s.get('type') in ('video', 'flexcontenthero')) + display_id)['stack'] if s.get('type') in ('video', 'flexcontenthero')) else: webpage = self._download_webpage( f'http://{domain}/embed/{video_id}', video_id, headers={'user-agent': self._USER_AGENT}) @@ -128,7 +128,7 @@ def _real_extract(self, url): if '/emea-exit/' in flavor_url: webpage = self._download_webpage(flavor_url, display_id, headers={'user-agent': self._USER_AGENT}, note=False) flavor_url = self._search_regex(r'rel="canonical" href="([^"]+)', - webpage, 'redirect url') + webpage, 'redirect url') if not flavor_url or not re.match(r'https?://', flavor_url) or flavor_format == 'mp4_access': continue tbr = int_or_none(flavor.get('bitrate')) @@ -182,7 +182,7 @@ def _real_extract(self, url): 'description': video_data.get('description') or video_data.get('short_desc'), 'thumbnail': video_data.get('thumb') or video_data.get('thumb_secure'), 'duration': int_or_none(video_data.get('duration_sec')), - 'upload_date': unified_strdate(video_data.get('publish_date')) or re.sub(r'\D', '', video_data.get('content_date').split('T')[0]), + 'upload_date': unified_strdate(video_data.get('publish_date')) or re.sub(r'\D', '', video_data.get('content_date', '').split('T')[0]), 'formats': formats, 'subtitles': subtitles, } From 98a8c6d6cccac7cbf300b4ca96c997b78e1f311c Mon Sep 17 00:00:00 2001 From: MrDemocracy Date: Thu, 21 Nov 2024 23:56:35 +0100 Subject: [PATCH 4/4] [disney] Implement code review suggestions --- yt_dlp/extractor/disney.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/yt_dlp/extractor/disney.py b/yt_dlp/extractor/disney.py index 0aa34568c1..f169d6c372 100644 --- a/yt_dlp/extractor/disney.py +++ b/yt_dlp/extractor/disney.py @@ -104,8 +104,7 @@ def _real_extract(self, url): grill = re.sub(r'"\s*\+\s*"', '', self._search_regex( r'Grill\.burger\s*=\s*({.+})\s*:', webpage, 'grill data')) - video_data = next(traverse_obj(s, ('data', 0, 'video')) or traverse_obj(s, ('data', 0)) for s in self._parse_json(grill, - display_id)['stack'] if s.get('type') in ('video', 'flexcontenthero')) + video_data = next(traverse_obj(s, ('data', 0, 'video'), ('data', 0)) for s in self._parse_json(grill, display_id)['stack'] if s.get('type') in ('video', 'flexcontenthero')) else: webpage = self._download_webpage( f'http://{domain}/embed/{video_id}', video_id, headers={'user-agent': self._USER_AGENT}) @@ -126,9 +125,8 @@ def _real_extract(self, url): flavor_format = flavor.get('format') flavor_url = flavor.get('url') if '/emea-exit/' in flavor_url: - webpage = self._download_webpage(flavor_url, display_id, headers={'user-agent': self._USER_AGENT}, note=False) - flavor_url = self._search_regex(r'rel="canonical" href="([^"]+)', - webpage, 'redirect url') + webpage = self._download_webpage(flavor_url, display_id, headers={'user-agent': self._USER_AGENT}, note=f"Resolving format URL redirect: {flavor_format} {flavor.get('height')}p") + flavor_url = self._search_regex(r'rel="canonical" href="([^"]+)', webpage, 'redirect url') if not flavor_url or not re.match(r'https?://', flavor_url) or flavor_format == 'mp4_access': continue tbr = int_or_none(flavor.get('bitrate'))