|
|
@ -359,15 +359,16 @@ class YoutubeIE(InfoExtractor):
|
|
|
|
# closed captions
|
|
|
|
# closed captions
|
|
|
|
video_subtitles = None
|
|
|
|
video_subtitles = None
|
|
|
|
if self._downloader.params.get('writesubtitles', False):
|
|
|
|
if self._downloader.params.get('writesubtitles', False):
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.report_video_subtitles_download(video_id)
|
|
|
|
self.report_video_subtitles_download(video_id)
|
|
|
|
request = urllib2.Request('http://video.google.com/timedtext?hl=en&type=list&v=%s' % video_id)
|
|
|
|
request = urllib2.Request('http://video.google.com/timedtext?hl=en&type=list&v=%s' % video_id)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
srt_list = urllib2.urlopen(request).read()
|
|
|
|
srt_list = urllib2.urlopen(request).read()
|
|
|
|
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
|
|
|
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
|
|
|
self._downloader.trouble(u'WARNING: unable to download video subtitles: %s' % str(err))
|
|
|
|
raise Trouble(u'WARNING: unable to download video subtitles: %s' % str(err))
|
|
|
|
else:
|
|
|
|
|
|
|
|
srt_lang_list = re.findall(r'lang_code="([\w\-]+)"', srt_list)
|
|
|
|
srt_lang_list = re.findall(r'lang_code="([\w\-]+)"', srt_list)
|
|
|
|
if srt_lang_list:
|
|
|
|
if not srt_lang_list:
|
|
|
|
|
|
|
|
raise Trouble(u'WARNING: video has no closed captions')
|
|
|
|
if self._downloader.params.get('subtitleslang', False):
|
|
|
|
if self._downloader.params.get('subtitleslang', False):
|
|
|
|
srt_lang = self._downloader.params.get('subtitleslang')
|
|
|
|
srt_lang = self._downloader.params.get('subtitleslang')
|
|
|
|
elif 'en' in srt_lang_list:
|
|
|
|
elif 'en' in srt_lang_list:
|
|
|
@ -375,17 +376,15 @@ class YoutubeIE(InfoExtractor):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
srt_lang = srt_lang_list[0]
|
|
|
|
srt_lang = srt_lang_list[0]
|
|
|
|
if not srt_lang in srt_lang_list:
|
|
|
|
if not srt_lang in srt_lang_list:
|
|
|
|
self._downloader.trouble(u'WARNING: no closed captions found in the specified language')
|
|
|
|
raise Trouble(u'WARNING: no closed captions found in the specified language')
|
|
|
|
else:
|
|
|
|
|
|
|
|
request = urllib2.Request('http://video.google.com/timedtext?hl=en&lang=%s&v=%s' % (srt_lang, video_id))
|
|
|
|
request = urllib2.Request('http://video.google.com/timedtext?hl=en&lang=%s&v=%s' % (srt_lang, video_id))
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
srt_xml = urllib2.urlopen(request).read()
|
|
|
|
srt_xml = urllib2.urlopen(request).read()
|
|
|
|
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
|
|
|
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
|
|
|
self._downloader.trouble(u'WARNING: unable to download video subtitles: %s' % str(err))
|
|
|
|
raise Trouble(u'WARNING: unable to download video subtitles: %s' % str(err))
|
|
|
|
else:
|
|
|
|
|
|
|
|
video_subtitles = self._closed_captions_xml_to_srt(srt_xml.decode('utf-8'))
|
|
|
|
video_subtitles = self._closed_captions_xml_to_srt(srt_xml.decode('utf-8'))
|
|
|
|
else:
|
|
|
|
except Trouble as trouble:
|
|
|
|
self._downloader.trouble(u'WARNING: video has no closed captions')
|
|
|
|
self._downloader.trouble(trouble[0])
|
|
|
|
|
|
|
|
|
|
|
|
# token
|
|
|
|
# token
|
|
|
|
video_token = urllib.unquote_plus(video_info['token'][0])
|
|
|
|
video_token = urllib.unquote_plus(video_info['token'][0])
|
|
|
|