aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/YoutubeDL.py2
-rw-r--r--youtube_dl/__init__.py12
-rw-r--r--youtube_dl/extractor/subtitles.py33
-rw-r--r--youtube_dl/extractor/youtube.py2
4 files changed, 29 insertions, 20 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index 1fd610a6e..e9f29e680 100644
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -76,7 +76,7 @@ class YoutubeDL(object):
allsubtitles: Downloads all the subtitles of the video
listsubtitles: Lists all available subtitles for the video
subtitlesformat: Subtitle format [srt/sbv/vtt] (default=srt)
- subtitleslang: Language of the subtitles to download
+ subtitleslangs: Language of the subtitles to download
keepvideo: Keep the video file after post-processing
daterange: A DateRange object, download only if the upload_date is in the range.
skip_download: Skip the actual download of the video file
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
index 5d686a928..2c2fd441c 100644
--- a/youtube_dl/__init__.py
+++ b/youtube_dl/__init__.py
@@ -83,6 +83,9 @@ def parseOpts(overrideArguments=None):
return "".join(opts)
+ def _comma_separated_values_options_callback(option, opt_str, value, parser):
+ setattr(parser.values, option.dest, value.split(','))
+
def _find_term_columns():
columns = os.environ.get('COLUMNS', None)
if columns:
@@ -203,9 +206,10 @@ def parseOpts(overrideArguments=None):
subtitles.add_option('--sub-format',
action='store', dest='subtitlesformat', metavar='FORMAT',
help='subtitle format (default=srt) ([sbv/vtt] youtube only)', default='srt')
- subtitles.add_option('--sub-lang', '--srt-lang',
- action='store', dest='subtitleslang', metavar='LANG',
- help='language of the subtitles to download (optional) use IETF language tags like \'en\'')
+ subtitles.add_option('--sub-lang', '--sub-langs', '--srt-lang',
+ action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
+ default=[], callback=_comma_separated_values_options_callback,
+ help='languages of the subtitles to download (optional) separated by commas, use IETF language tags like \'en,pt\'')
downloader.add_option('-r', '--rate-limit',
dest='ratelimit', metavar='LIMIT', help='maximum download rate (e.g. 50k or 44.6m)')
@@ -570,7 +574,7 @@ def _real_main(argv=None):
'allsubtitles': opts.allsubtitles,
'listsubtitles': opts.listsubtitles,
'subtitlesformat': opts.subtitlesformat,
- 'subtitleslang': opts.subtitleslang,
+ 'subtitleslangs': opts.subtitleslangs,
'matchtitle': decodeOption(opts.matchtitle),
'rejecttitle': decodeOption(opts.rejecttitle),
'max_downloads': opts.max_downloads,
diff --git a/youtube_dl/extractor/subtitles.py b/youtube_dl/extractor/subtitles.py
index caacea5fe..c10cdf266 100644
--- a/youtube_dl/extractor/subtitles.py
+++ b/youtube_dl/extractor/subtitles.py
@@ -21,24 +21,29 @@ class SubtitlesIE(InfoExtractor):
def _extract_subtitles(self, video_id):
""" returns {sub_lang: sub} or {} if subtitles not found """
- sub_lang_list = self._get_available_subtitles(video_id)
- if not sub_lang_list: # error, it didn't get the available subtitles
+ available_subs_list = self._get_available_subtitles(video_id)
+ if not available_subs_list: # error, it didn't get the available subtitles
return {}
+ if self._downloader.params.get('allsubtitles', False):
+ sub_lang_list = available_subs_list
+ else:
+ if self._downloader.params.get('writesubtitles', False):
+ if self._downloader.params.get('subtitleslangs', False):
+ requested_langs = self._downloader.params.get('subtitleslangs')
+ elif 'en' in available_subs_list:
+ requested_langs = ['en']
+ else:
+ requested_langs = [list(available_subs_list.keys())[0]]
- if self._downloader.params.get('writesubtitles', False):
- if self._downloader.params.get('subtitleslang', False):
- sub_lang = self._downloader.params.get('subtitleslang')
- elif 'en' in sub_lang_list:
- sub_lang = 'en'
- else:
- sub_lang = list(sub_lang_list.keys())[0]
- if not sub_lang in sub_lang_list:
- self._downloader.report_warning(u'no closed captions found in the specified language "%s"' % sub_lang)
- return {}
- sub_lang_list = {sub_lang: sub_lang_list[sub_lang]}
+ sub_lang_list = {}
+ for sub_lang in requested_langs:
+ if not sub_lang in available_subs_list:
+ self._downloader.report_warning(u'no closed captions found in the specified language "%s"' % sub_lang)
+ continue
+ sub_lang_list[sub_lang] = available_subs_list[sub_lang]
subtitles = {}
- for sub_lang, url in sub_lang_list.iteritems():
+ for sub_lang, url in sub_lang_list.items():
subtitle = self._request_subtitle_url(sub_lang, url)
if subtitle:
subtitles[sub_lang] = subtitle
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index 370cc64cc..b3400df0a 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -160,7 +160,7 @@ class YoutubeSubtitlesIE(SubtitlesIE):
def _request_automatic_caption(self, video_id, webpage):
"""We need the webpage for getting the captions url, pass it as an
argument to speed up the process."""
- sub_lang = self._downloader.params.get('subtitleslang') or 'en'
+ sub_lang = (self._downloader.params.get('subtitleslangs') or ['en'])[0]
sub_format = self._downloader.params.get('subtitlesformat')
self.to_screen(u'%s: Looking for automatic captions' % video_id)
mobj = re.search(r';ytplayer.config = ({.*?});', webpage)