[brightcove] Fix subtitles extraction (closes #25540)
authorSergey M․ <dstftw@gmail.com>
Fri, 5 Jun 2020 16:33:14 +0000 (23:33 +0700)
committerSergey M․ <dstftw@gmail.com>
Fri, 5 Jun 2020 16:33:14 +0000 (23:33 +0700)
youtube_dl/extractor/brightcove.py

index 85001b3ad3cf100d093a16806085b02fa5933d5a..462815317b737668a1eb7c140564d8834c626e93 100644 (file)
@@ -25,9 +25,11 @@ from ..utils import (
     int_or_none,
     parse_iso8601,
     smuggle_url,
+    str_or_none,
     unescapeHTML,
     unsmuggle_url,
     update_url_query,
+    url_or_none,
     clean_html,
     mimetype2ext,
     UnsupportedError,
@@ -553,10 +555,16 @@ class BrightcoveNewIE(AdobePassIE):
 
         subtitles = {}
         for text_track in json_data.get('text_tracks', []):
-            if text_track.get('src'):
-                subtitles.setdefault(text_track.get('srclang'), []).append({
-                    'url': text_track['src'],
-                })
+            if text_track.get('kind') != 'captions':
+                continue
+            text_track_url = url_or_none(text_track.get('src'))
+            if not text_track_url:
+                continue
+            lang = (str_or_none(text_track.get('srclang'))
+                    or str_or_none(text_track.get('label')) or 'en').lower()
+            subtitles.setdefault(lang, []).append({
+                'url': text_track_url,
+            })
 
         is_live = False
         duration = float_or_none(json_data.get('duration'), 1000)