aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/FileDownloader.py
diff options
context:
space:
mode:
authorIsmael Mejia <iemejia@gmail.com>2013-02-22 02:52:55 +0100
committerFilippo Valsorda <filippo.valsorda@gmail.com>2013-03-20 08:41:53 +0100
commitae608b8076497d70e2a95e5e939c1fb31e2dde53 (patch)
treeb61cdb2a029df436b4fcfd11a5db108bcd69d5d6 /youtube_dl/FileDownloader.py
parentcdb130b09a16865b81fd34d19b74fa634d45cad7 (diff)
downloadyoutube-dl-ae608b8076497d70e2a95e5e939c1fb31e2dde53.tar.xz
Added new option '--all-srt' to download all the subtitles of a video.
Only works in youtube for the moment.
Diffstat (limited to 'youtube_dl/FileDownloader.py')
-rw-r--r--youtube_dl/FileDownloader.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py
index 487c9dadb..e496b8a8d 100644
--- a/youtube_dl/FileDownloader.py
+++ b/youtube_dl/FileDownloader.py
@@ -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'