From 0345a064a7db7823433d5c0ee9504eb7adb070f6 Mon Sep 17 00:00:00 2001 From: df Date: Wed, 9 Jun 2021 12:32:35 +0100 Subject: [PATCH] [itv] fixed extraction (closes ytdl-org#28906) https://github.com/ytdl-org/youtube-dl/pull/28955 (@sleaux-meaux) ITV changes require media stream and subtitles to be taken from different playlist resources. Incorporates suggestion in ytdl-org#28906 (comment) --- youtube_dl/extractor/itv.py | 58 +++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/youtube_dl/extractor/itv.py b/youtube_dl/extractor/itv.py index e86c40b42..58773b161 100644 --- a/youtube_dl/extractor/itv.py +++ b/youtube_dl/extractor/itv.py @@ -15,6 +15,7 @@ from ..utils import ( merge_dicts, parse_duration, smuggle_url, + try_get, url_or_none, ) @@ -23,15 +24,20 @@ class ITVIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?itv\.com/hub/[^/]+/(?P[0-9a-zA-Z]+)' _GEO_COUNTRIES = ['GB'] _TESTS = [{ - 'url': 'https://www.itv.com/hub/liar/2a4547a0012', + 'url': 'https://www.itv.com/hub/the-durrells/2a4156a0001', 'info_dict': { - 'id': '2a4547a0012', + 'id': '2a4156a0001', 'ext': 'mp4', - 'title': 'Liar - Series 2 - Episode 6', - 'description': 'md5:d0f91536569dec79ea184f0a44cca089', - 'series': 'Liar', - 'season_number': 2, - 'episode_number': 6, + 'title': 'The Durrells - Series 1 - Episode 1', + 'description': 'md5:43ae58e27aa91720fc933a68a37e9e95', + 'series': 'The Durrells', + 'season_number': 1, + 'episode_number': 1, + 'subtitles': { + 'en': [ + {'url': 'https://itvpnpsubtitles.content.itv.com/2-4156-0001-003/Subtitles/3/WebVTT-OUT-OF-BAND/2-4156-0001-003_Series1590486890_TX000000.vtt'} + ] + }, }, 'params': { # m3u8 download @@ -87,13 +93,13 @@ class ITVIE(InfoExtractor): }, 'variantAvailability': { 'featureset': { - 'min': ['hls', 'aes', 'outband-webvtt'], - 'max': ['hls', 'aes', 'outband-webvtt'] + 'min': ['hls', 'aes'], + 'max': ['hls', 'aes'] }, - 'platformTag': 'dotcom' + 'platformTag': 'mobile' } }).encode(), headers=headers) - video_data = ios_playlist['Playlist']['Video'] + video_data = try_get(ios_playlist, lambda x: x['Playlist']['Video'], dict) or {} ios_base_url = video_data.get('Base') formats = [] @@ -114,8 +120,36 @@ class ITVIE(InfoExtractor): }) self._sort_formats(formats) + subs_playlist = self._download_json( + ios_playlist_url, video_id, data=json.dumps({ + 'user': { + 'itvUserId': '', + 'entitlements': [], + 'token': '' + }, + 'device': { + 'manufacturer': 'Safari', + 'model': '5', + 'os': { + 'name': 'Windows NT', + 'version': '6.1', + 'type': 'desktop' + } + }, + 'client': { + 'version': '4.1', + 'id': 'browser' + }, + 'variantAvailability': { + 'featureset': { + 'min': ['mpeg-dash', 'widevine', 'outband-webvtt'], + 'max': ['mpeg-dash', 'widevine', 'outband-webvtt'] + }, + 'platformTag': 'mobile' + } + }).encode(), headers=headers) + subs = try_get(subs_playlist, lambda x: x['Playlist']['Video']['Subtitles'], list) or [] subtitles = {} - subs = video_data.get('Subtitles') or [] for sub in subs: if not isinstance(sub, dict): continue