mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-04-04 14:10:13 -05:00
[YouTube] Get subtitles/automatic captions from both web and API responses
This commit is contained in:
parent
da7223d4aa
commit
2239ee7965
@ -2136,7 +2136,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
video_details = merge_dicts(*traverse_obj(
|
video_details = merge_dicts(*traverse_obj(
|
||||||
(player_response, api_player_response),
|
(player_response, api_player_response),
|
||||||
(Ellipsis, 'videoDetails', T(dict))))
|
(Ellipsis, 'videoDetails', T(dict))))
|
||||||
player_response.update(api_player_response or {})
|
player_response.update(filter_dict(
|
||||||
|
api_player_response or {}, cndn=lambda k, _: k != 'captions'))
|
||||||
player_response['videoDetails'] = video_details
|
player_response['videoDetails'] = video_details
|
||||||
|
|
||||||
def is_agegated(playability):
|
def is_agegated(playability):
|
||||||
@ -2566,8 +2567,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
}
|
}
|
||||||
|
|
||||||
pctr = traverse_obj(
|
pctr = traverse_obj(
|
||||||
player_response,
|
(player_response, api_player_response),
|
||||||
('captions', 'playerCaptionsTracklistRenderer', T(dict)))
|
(Ellipsis, 'captions', 'playerCaptionsTracklistRenderer', T(dict)))
|
||||||
if pctr:
|
if pctr:
|
||||||
def process_language(container, base_url, lang_code, query):
|
def process_language(container, base_url, lang_code, query):
|
||||||
lang_subs = []
|
lang_subs = []
|
||||||
@ -2584,20 +2585,19 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
def process_subtitles():
|
def process_subtitles():
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
for caption_track in traverse_obj(pctr, (
|
for caption_track in traverse_obj(pctr, (
|
||||||
'captionTracks', lambda _, v: v.get('baseUrl'))):
|
Ellipsis, 'captionTracks', lambda _, v: (
|
||||||
|
v.get('baseUrl') and v.get('languageCode')))):
|
||||||
base_url = self._yt_urljoin(caption_track['baseUrl'])
|
base_url = self._yt_urljoin(caption_track['baseUrl'])
|
||||||
if not base_url:
|
if not base_url:
|
||||||
continue
|
continue
|
||||||
|
lang_code = caption_track['languageCode']
|
||||||
if caption_track.get('kind') != 'asr':
|
if caption_track.get('kind') != 'asr':
|
||||||
lang_code = caption_track.get('languageCode')
|
|
||||||
if not lang_code:
|
|
||||||
continue
|
|
||||||
process_language(
|
process_language(
|
||||||
subtitles, base_url, lang_code, {})
|
subtitles, base_url, lang_code, {})
|
||||||
continue
|
continue
|
||||||
automatic_captions = {}
|
automatic_captions = {}
|
||||||
for translation_language in traverse_obj(pctr, (
|
for translation_language in traverse_obj(pctr, (
|
||||||
'translationLanguages', lambda _, v: v.get('languageCode'))):
|
Ellipsis, 'translationLanguages', lambda _, v: v.get('languageCode'))):
|
||||||
translation_language_code = translation_language['languageCode']
|
translation_language_code = translation_language['languageCode']
|
||||||
process_language(
|
process_language(
|
||||||
automatic_captions, base_url, translation_language_code,
|
automatic_captions, base_url, translation_language_code,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user