From 9b74c4b7db073835ac5eaf53da9312258540e6d9 Mon Sep 17 00:00:00 2001 From: dirkf Date: Tue, 13 Oct 2020 13:38:45 +0000 Subject: [PATCH] Handle subtitles properly The subtitles are parsed from each mediaselector playlist in the form of a dict keyed by language each of whose values is a list containing a dict keyed by url and sttl type. There seems to be no attempt in the extractor to make this list contain more than one dict. So a strategy is needed to deal with multiple sttl types for the same language. For backward compatibility, let the first of any duplicate sttl languages take precedence. --- youtube_dl/extractor/bbc.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/bbc.py b/youtube_dl/extractor/bbc.py index 76dfa0598..754516b6a 100644 --- a/youtube_dl/extractor/bbc.py +++ b/youtube_dl/extractor/bbc.py @@ -359,12 +359,17 @@ class BBCCoUkIE(InfoExtractor): try: formatsAndSubtitles = self._download_media_selector_url( mediaselector_url % programme_id, programme_id) - # formats should always be set, but just in case + # formats (a list) should always be set, but just in case if formatsAndSubtitles[0]: formats += formatsAndSubtitles[0] - # subtitles may never be set + # subtitles subtitles (a dict {(lang,sttl)}) if formatsAndSubtitles[1]: - subtitles += formatsAndSubtitles[1] + if not subtitles: + subtitles = formatsAndSubtitles[1] + else: + # prioritise the first sttl for each lang + formatsAndSubtitles[1].update(subtitles) + subtitles = formatsAndSubtitles[1] except BBCCoUkIE.MediaSelectionError as e: if e.id in ('notukerror', 'geolocation', 'selectionunavailable'): last_exception = e