[ted] fixed error in case of no subtitles present
authorIsmaël Mejía <iemejia@gmail.com>
Tue, 5 Nov 2013 11:00:13 +0000 (12:00 +0100)
committerIsmaël Mejía <iemejia@gmail.com>
Tue, 5 Nov 2013 11:00:13 +0000 (12:00 +0100)
I created a test, but I leave it commented since TED videos get
new subtitles frequently.

test/test_ted_subtitles.py
youtube_dl/extractor/ted.py

index 3283253ab95a3d1996c909d395e98df242a0055c..a0dd7eeed1e8422b9ed52754316867b40ffeb8f7 100644 (file)
@@ -51,6 +51,12 @@ class TestTedSubtitles(unittest.TestCase):
         self.DL.params['subtitleslang'] = ['en']
         subtitles = self.getSubtitles()
         self.assertTrue(len(subtitles.keys()) == 0)
+    # def test_nosubtitles(self):
+    #     self.DL.expect_warning(u'video doesn\'t have subtitles')
+    #     self.url = 'http://www.ted.com/talks/rodrigo_canales_the_deadly_genius_of_drug_cartels.html'
+    #     self.DL.params['writesubtitles'] = True
+    #     self.DL.params['allsubtitles'] = True
+    #     subtitles = self.getSubtitles()
     def test_multiple_langs(self):
         self.DL.params['writesubtitles'] = True
         langs = ['es', 'fr', 'de']
index 239e2a4482ea6bbf03089181e1301f9a12cbde5b..1b006bc9bc890bcc373c68a262c56c88a8686a09 100644 (file)
@@ -3,6 +3,11 @@ import re
 
 from .subtitles import SubtitlesInfoExtractor
 
+from ..utils import (
+    compat_str,
+    RegexNotFoundError,
+)
+
 class TEDIE(SubtitlesInfoExtractor):
     _VALID_URL=r'''http://www\.ted\.com/
                    (
@@ -105,12 +110,15 @@ class TEDIE(SubtitlesInfoExtractor):
         return info
 
     def _get_available_subtitles(self, video_id, webpage):
-        options = self._search_regex(r'(?:<select name="subtitles_language_select" id="subtitles_language_select">)(.*?)(?:</select>)', webpage, 'subtitles_language_select', flags=re.DOTALL)
-        languages = re.findall(r'(?:<option value=")(\S+)"', options)
-        if languages:
-            sub_lang_list = {}
-            for l in languages:
-                url = 'http://www.ted.com/talks/subtitles/id/%s/lang/%s/format/srt' % (video_id, l)
-                sub_lang_list[l] = url
-            return sub_lang_list
+        try:
+            options = self._search_regex(r'(?:<select name="subtitles_language_select" id="subtitles_language_select">)(.*?)(?:</select>)', webpage, 'subtitles_language_select', flags=re.DOTALL)
+            languages = re.findall(r'(?:<option value=")(\S+)"', options)
+            if languages:
+                sub_lang_list = {}
+                for l in languages:
+                    url = 'http://www.ted.com/talks/subtitles/id/%s/lang/%s/format/srt' % (video_id, l)
+                    sub_lang_list[l] = url
+                return sub_lang_list
+        except RegexNotFoundError as err:
+            self._downloader.report_warning(u'video doesn\'t have subtitles')
         return {}