From 774d79cc4c352e0665c722055cb7c8fb776b3199 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 13 May 2021 16:49:40 +0530 Subject: [PATCH] [youtube] Add language names Co-authored by: nixxo, tpikonen Based on: https://github.com/ytdl-org/youtube-dl/pull/26112 Closes: #310 --- yt_dlp/extractor/youtube.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 51abeb2db..75675bb3c 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -2186,7 +2186,7 @@ def feed_entry(name): lambda x: x['captions']['playerCaptionsTracklistRenderer'], dict) subtitles = {} if pctr: - def process_language(container, base_url, lang_code, query): + def process_language(container, base_url, lang_code, sub_name, query): lang_subs = container.setdefault(lang_code, []) for fmt in self._SUBTITLE_FORMATS: query.update({ @@ -2195,6 +2195,7 @@ def process_language(container, base_url, lang_code, query): lang_subs.append({ 'ext': fmt, 'url': update_url_query(base_url, query), + 'name': sub_name, }) for caption_track in (pctr.get('captionTracks') or []): @@ -2208,7 +2209,9 @@ def process_language(container, base_url, lang_code, query): if not lang_code: continue process_language( - subtitles, base_url, lang_code, {}) + subtitles, base_url, lang_code, + try_get(caption_track, lambda x: x.get('name').get('simpleText')), + {}) continue automatic_captions = {} for translation_language in (pctr.get('translationLanguages') or []): @@ -2217,6 +2220,7 @@ def process_language(container, base_url, lang_code, query): continue process_language( automatic_captions, base_url, translation_language_code, + try_get(translation_language, lambda x: x['languageName']['simpleText']), {'tlang': translation_language_code}) info['automatic_captions'] = automatic_captions info['subtitles'] = subtitles