]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
[ted] Fix subtitles extraction (closes #13628, closes #13629)
authorSergey M․ <dstftw@gmail.com>
Tue, 11 Jul 2017 14:36:45 +0000 (21:36 +0700)
committerSergey M․ <dstftw@gmail.com>
Tue, 11 Jul 2017 14:36:45 +0000 (21:36 +0700)
youtube_dl/extractor/ted.py

index f27d0e31392451adc75a934ab3164d52ee79b8c4..06a27fd0428b469abb64e6428faf263fc080cc33 100644 (file)
@@ -271,20 +271,22 @@ class TEDIE(InfoExtractor):
         }
 
     def _get_subtitles(self, video_id, talk_info):
-        languages = [lang['languageCode'] for lang in talk_info.get('languages', [])]
-        if languages:
-            sub_lang_list = {}
-            for l in languages:
-                sub_lang_list[l] = [
-                    {
-                        'url': 'http://www.ted.com/talks/subtitles/id/%s/lang/%s/format/%s' % (video_id, l, ext),
-                        'ext': ext,
-                    }
-                    for ext in ['ted', 'srt']
-                ]
-            return sub_lang_list
-        else:
-            return {}
+        sub_lang_list = {}
+        for language in try_get(
+                talk_info,
+                (lambda x: x['downloads']['languages'],
+                 lambda x: x['languages']), list):
+            lang_code = language.get('languageCode') or language.get('ianaCode')
+            if not lang_code:
+                continue
+            sub_lang_list[lang_code] = [
+                {
+                    'url': 'http://www.ted.com/talks/subtitles/id/%s/lang/%s/format/%s' % (video_id, lang_code, ext),
+                    'ext': ext,
+                }
+                for ext in ['ted', 'srt']
+            ]
+        return sub_lang_list
 
     def _watch_info(self, url, name):
         webpage = self._download_webpage(url, name)