[itv] Prefer last matching featureset (#1001)

Bug fix for #986
Authored by: coletdjnz
This commit is contained in:
coletdjnz 2021-09-17 20:55:49 +00:00 committed by GitHub
parent d1b39ad844
commit 298bf1d275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -113,12 +113,15 @@ class ITVIE(InfoExtractor):
def _get_subtitles(self, video_id, variants, ios_playlist_url, headers, *args, **kwargs): def _get_subtitles(self, video_id, variants, ios_playlist_url, headers, *args, **kwargs):
subtitles = {} subtitles = {}
# Prefer last matching featureset
# See: https://github.com/yt-dlp/yt-dlp/issues/986
platform_tag_subs, featureset_subs = next( platform_tag_subs, featureset_subs = next(
((platform_tag, featureset) ((platform_tag, featureset)
for platform_tag, featuresets in variants.items() for featureset in featuresets for platform_tag, featuresets in reversed(variants.items()) for featureset in featuresets
if try_get(featureset, lambda x: x[2]) == 'outband-webvtt'), if try_get(featureset, lambda x: x[2]) == 'outband-webvtt'),
(None, None)) (None, None))
if platform_tag_subs or featureset_subs:
if platform_tag_subs and featureset_subs:
subs_playlist = self._call_api( subs_playlist = self._call_api(
video_id, ios_playlist_url, headers, platform_tag_subs, featureset_subs, fatal=False) video_id, ios_playlist_url, headers, platform_tag_subs, featureset_subs, fatal=False)
subs = try_get(subs_playlist, lambda x: x['Playlist']['Video']['Subtitles'], list) or [] subs = try_get(subs_playlist, lambda x: x['Playlist']['Video']['Subtitles'], list) or []
@ -139,9 +142,11 @@ class ITVIE(InfoExtractor):
variants = self._parse_json( variants = self._parse_json(
try_get(params, lambda x: x['data-video-variants'], compat_str) or '{}', try_get(params, lambda x: x['data-video-variants'], compat_str) or '{}',
video_id, fatal=False) video_id, fatal=False)
# Prefer last matching featureset
# See: https://github.com/yt-dlp/yt-dlp/issues/986
platform_tag_video, featureset_video = next( platform_tag_video, featureset_video = next(
((platform_tag, featureset) ((platform_tag, featureset)
for platform_tag, featuresets in variants.items() for featureset in featuresets for platform_tag, featuresets in reversed(variants.items()) for featureset in featuresets
if try_get(featureset, lambda x: x[:2]) == ['hls', 'aes']), if try_get(featureset, lambda x: x[:2]) == ['hls', 'aes']),
(None, None)) (None, None))
if not platform_tag_video or not featureset_video: if not platform_tag_video or not featureset_video: