Added new option '--all-srt' to download all the subtitles of a video.

Only works in youtube for the moment.
This commit is contained in:
Ismael Mejia 2013-02-22 02:52:55 +01:00 committed by Filippo Valsorda
parent cdb130b09a
commit ae608b8076
5 changed files with 107 additions and 35 deletions

View file

@ -80,6 +80,7 @@ class FileDownloader(object):
writeinfojson: Write the video description to a .info.json file
writesubtitles: Write the video subtitles to a .srt file
onlysubtitles: Downloads only the subtitles of the video
allsubtitles: Downloads all the subtitles of the video
subtitleslang: Language of the subtitles to download
test: Download only first bytes to test the downloader.
keepvideo: Keep the video file after post-processing
@ -442,18 +443,33 @@ class FileDownloader(object):
if self.params.get('writesubtitles', False) and 'subtitles' in info_dict and info_dict['subtitles']:
# subtitles download errors are already managed as troubles in relevant IE
# that way it will silently go on when used with unsupporting IE
subtitle = info_dict['subtitles'][0]
(srt_error, srt_lang, srt) = subtitle
try:
srtfn = filename.rsplit('.', 1)[0] + u'.srt'
if self.params.get('subtitleslang', False):
srtfn = filename.rsplit('.', 1)[0] + u'.' + self.params['subtitleslang'] + u'.srt'
srtfn = filename.rsplit('.', 1)[0] + u'.' + srt_lang + u'.srt'
self.report_writesubtitles(srtfn)
with io.open(encodeFilename(srtfn), 'w', encoding='utf-8') as srtfile:
srtfile.write(info_dict['subtitles'])
if self.params.get('onlysubtitles', False):
return
srtfile.write(srt)
except (OSError, IOError):
self.trouble(u'ERROR: Cannot write subtitles file ' + descfn)
return
if self.params.get('onlysubtitles', False):
return
if self.params.get('allsubtitles', False) and 'subtitles' in info_dict and info_dict['subtitles']:
subtitles = info_dict['subtitles']
for subtitle in subtitles:
(srt_error, srt_lang, srt) = subtitle
try:
srtfn = filename.rsplit('.', 1)[0] + u'.' + srt_lang + u'.srt'
self.report_writesubtitles(srtfn)
with io.open(encodeFilename(srtfn), 'w', encoding='utf-8') as srtfile:
srtfile.write(srt)
except (OSError, IOError):
self.trouble(u'ERROR: Cannot write subtitles file ' + descfn)
return
if self.params.get('onlysubtitles', False):
return
if self.params.get('writeinfojson', False):
infofn = filename + u'.info.json'