[ie/crunchyroll] Make aditional audio languages available

pull/9867/head
Oliver Hattshire 4 weeks ago
parent ac817bc83e
commit 6b90338932

@ -175,17 +175,41 @@ class CrunchyrollBaseIE(InfoExtractor):
display_id = identifier
self._update_auth()
stream_url = 'https://cr-play-service.prd.crunchyrollsvc.com/v1/{}/console/switch/play'
stream_response = self._download_json(
f'https://cr-play-service.prd.crunchyrollsvc.com/v1/{identifier}/console/switch/play',
stream_url.format(identifier),
display_id, note='Downloading stream info', errnote='Failed to download stream info',
headers=CrunchyrollBaseIE._AUTH_HEADERS)
default_audio_locale = traverse_obj(stream_response, ('audioLocale', {str}))
available_formats = {}
stream_variants = {}
variant_obj_check = lambda _, v: v['guid'] and v['audio_locale']
for audio_locale_variant in traverse_obj(stream_response, ('versions', variant_obj_check)):
locale = audio_locale_variant['audio_locale']
is_original_stream = traverse_obj(audio_locale_variant, ('original', {bool}), default = False)
stream_variants[locale] = self._download_json(
stream_url.format(audio_locale_variant['guid']),
display_id, note=f'Downloading {locale} stream info', errnote=f'Failed to download {locale} stream info',
headers=CrunchyrollBaseIE._AUTH_HEADERS)
if is_original_stream:
stream_variants['original'] = stream_variants[locale]
available_formats[f'audio_{locale}'] = (f'audio-{locale}', '', locale, stream_variants['original']['url'])
if not stream_variants:
stream_variants['original'] = stream_response
available_formats['original'] = ('original', '', default_audio_locale, stream_variants['original']['url'])
available_formats = {'': ('', '', stream_response['url'])}
for hardsub_lang, stream in traverse_obj(stream_response, ('hardSubs', {dict.items}, lambda _, v: v[1]['url'])):
available_formats[hardsub_lang] = (f'hardsub-{hardsub_lang}', hardsub_lang, stream['url'])
available_formats[f'hardsub_{hardsub_lang}'] = (f'hardsub-{hardsub_lang}', hardsub_lang, default_audio_locale, stream['url'])
requested_hardsubs = [('' if val == 'none' else val) for val in (self._configuration_arg('hardsub') or ['none'])]
hardsub_langs = [lang for lang in available_formats if lang]
hardsub_langs = [lang.replace('hardsub_', '') for lang in available_formats if lang.startswith('hardsub_')]
if hardsub_langs and 'all' not in requested_hardsubs:
full_format_langs = set(requested_hardsubs)
self.to_screen(f'Available hardsub languages: {", ".join(hardsub_langs)}')
@ -197,14 +221,13 @@ class CrunchyrollBaseIE(InfoExtractor):
else:
full_format_langs = set(map(str.lower, available_formats))
audio_locale = traverse_obj(stream_response, ('audioLocale', {str}))
hardsub_preference = qualities(requested_hardsubs[::-1])
formats, subtitles = [], {}
for format_id, hardsub_lang, stream_url in available_formats.values():
for format_id, hardsub_lang, audio_locale, stream_url in available_formats.values():
if hardsub_lang.lower() in full_format_langs:
adaptive_formats, dash_subs = self._extract_mpd_formats_and_subtitles(
stream_url, display_id, mpd_id=format_id, headers=CrunchyrollBaseIE._AUTH_HEADERS,
fatal=False, note=f'Downloading {f"{format_id} " if hardsub_lang else ""}MPD manifest')
fatal=False, note=f'Downloading {format_id} MPD manifest')
self._merge_subtitles(dash_subs, target=subtitles)
else:
continue # XXX: Update this if/when meta mpd formats are working

Loading…
Cancel
Save