diff options
Diffstat (limited to 'youtube_dl/FileDownloader.py')
| -rw-r--r-- | youtube_dl/FileDownloader.py | 28 | 
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' | 
