From ef8c0ad835654ae0d1defea0b2b9fa51fc4b6221 Mon Sep 17 00:00:00 2001 From: Madars Virza Date: Thu, 16 Apr 2020 14:04:43 -0400 Subject: [youtube] Fix download of auto-captions when subtitles are available When invoked with --write-auto-sub (but without --write-sub), youtube-dl should only download automatic captions. However, for some videos with both automatic captions and manual subtitles (e.g. 2klmuggOElE; accessed on 16.04.2020), youtube-dl selects the manual subtitle track regardless. This commit makes _get_automatic_captions prefer a renderer['captionTracks'] entry with 'kind' == 'asr', if one is available, as the 'kind=asr' parameter also distinguishes the baseUrl's (but one could also filter by vssId.startswith('a.')). diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index afaa12b1b..6d3a3bb56 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1519,6 +1519,14 @@ class YoutubeIE(YoutubeBaseInfoExtractor): if player_response: renderer = player_response['captions']['playerCaptionsTracklistRenderer'] base_url = renderer['captionTracks'][0]['baseUrl'] + # the first caption track might contain manual + # subtitles not auto-captions (e.g. 2klmuggOElE, + # accessed on 16.04.2020) so we look further in + # captionTracks and select a base_url from an + # explicitly marked asr track if one exists. + for track in renderer['captionTracks'][1:]: + if track.get('kind') == 'asr': + base_url = track['baseUrl'] sub_lang_list = [] for lang in renderer['translationLanguages']: lang_code = lang.get('languageCode')