Removed conversion from youtube closed caption format to srt since youtube api suppor...
authorIsmael Mejia <iemejia@gmail.com>
Thu, 21 Feb 2013 19:51:35 +0000 (20:51 +0100)
committerIsmael Mejia <iemejia@gmail.com>
Thu, 21 Feb 2013 19:51:35 +0000 (20:51 +0100)
test/test_youtube_subtitles.py
youtube_dl/InfoExtractors.py

index 5d3566a35f5a900ac3eb613de9877228c5a40aae..ff09ea459c6af8bf235cfb124f8f4d44ddb13060 100644 (file)
@@ -43,7 +43,7 @@ class TestYoutubeSubtitles(unittest.TestCase):
         DL.params['writesubtitles'] = True
         IE = YoutubeIE(DL)
         info_dict = IE.extract('QRS8MkLhQmM')
-        self.assertEqual(md5(info_dict[0]['subtitles']), 'c3228550d59116f3c29fba370b55d033')
+        self.assertEqual(md5(info_dict[0]['subtitles']), '4cd9278a35ba2305f47354ee13472260')
 
     def test_youtube_subtitles_it(self):
         DL = FakeDownloader()
@@ -51,7 +51,7 @@ class TestYoutubeSubtitles(unittest.TestCase):
         DL.params['subtitleslang'] = 'it'
         IE = YoutubeIE(DL)
         info_dict = IE.extract('QRS8MkLhQmM')
-        self.assertEqual(md5(info_dict[0]['subtitles']), '132a88a0daf8e1520f393eb58f1f646a')
+        self.assertEqual(md5(info_dict[0]['subtitles']), '164a51f16f260476a05b50fe4c2f161d')
 
 if __name__ == '__main__':
     unittest.main()
index d3c3ac2640447af6da4f42c48cb607a1383ace84..e3998fbe88173ae1cb949d2f6256fa0fc06fb530 100755 (executable)
@@ -228,23 +228,6 @@ class YoutubeIE(InfoExtractor):
         """Indicate the download will use the RTMP protocol."""
         self._downloader.to_screen(u'[youtube] RTMP download detected')
 
-    def _closed_captions_xml_to_srt(self, xml_string):
-        srt = ''
-        texts = re.findall(r'<text start="([\d\.]+)"( dur="([\d\.]+)")?>([^<]+)</text>', xml_string, re.MULTILINE)
-        # TODO parse xml instead of regex
-        for n, (start, dur_tag, dur, caption) in enumerate(texts):
-            if not dur: dur = '4'
-            start = float(start)
-            end = start + float(dur)
-            start = "%02i:%02i:%02i,%03i" %(start/(60*60), start/60%60, start%60, start%1*1000)
-            end = "%02i:%02i:%02i,%03i" %(end/(60*60), end/60%60, end%60, end%1*1000)
-            caption = unescapeHTML(caption)
-            caption = unescapeHTML(caption) # double cycle, intentional
-            srt += str(n+1) + '\n'
-            srt += start + ' --> ' + end + '\n'
-            srt += caption + '\n\n'
-        return srt
-
     def _extract_subtitles(self, video_id):
         self.report_video_subtitles_download(video_id)
         request = compat_urllib_request.Request('http://video.google.com/timedtext?hl=en&type=list&v=%s' % video_id)
@@ -268,15 +251,16 @@ class YoutubeIE(InfoExtractor):
             'lang': srt_lang,
             'name': srt_lang_list[srt_lang].encode('utf-8'),
             'v': video_id,
+            'fmt': 'srt',
         })
         url = 'http://www.youtube.com/api/timedtext?' + params
         try:
-            srt_xml = compat_urllib_request.urlopen(url).read().decode('utf-8')
+            srt = compat_urllib_request.urlopen(url).read().decode('utf-8')
         except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
             return (u'WARNING: unable to download video subtitles: %s' % compat_str(err), None)
-        if not srt_xml:
+        if not srt:
             return (u'WARNING: Did not fetch video subtitles', None)
-        return (None, self._closed_captions_xml_to_srt(srt_xml))
+        return (None, srt)
 
     def _print_formats(self, formats):
         print('Available formats:')