aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2013-06-25 23:45:16 +0200
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2013-06-25 23:46:24 +0200
commitb004821fa98a5ac563811f37b744c632dd58d559 (patch)
treee9ceb5130a6613803e1c08e472d07e4de14cff28 /youtube_dl
parent81b42336ad9a59167a2c936bbd58f818007b1872 (diff)
Add the option "--write-auto-sub" to download automatic subtitles from Youtube
Now automatic subtitles are only downloaded if the option is given. (closes #903)
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/YoutubeDL.py3
-rw-r--r--youtube_dl/__init__.py4
-rw-r--r--youtube_dl/extractor/youtube.py15
3 files changed, 13 insertions, 9 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index b4a966b70..e9a24a95a 100644
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -72,6 +72,7 @@ class YoutubeDL(object):
writeinfojson: Write the video description to a .info.json file
writethumbnail: Write the thumbnail image to a file
writesubtitles: Write the video subtitles to a file
+ writeautomaticsub: Write the automatic subtitles to a file
allsubtitles: Downloads all the subtitles of the video
listsubtitles: Lists all available subtitles for the video
subtitlesformat: Subtitle format [sbv/srt] (default=srt)
@@ -474,7 +475,7 @@ class YoutubeDL(object):
self.report_error(u'Cannot write description file ' + descfn)
return
- if self.params.get('writesubtitles', False) and 'subtitles' in info_dict and info_dict['subtitles']:
+ if (self.params.get('writesubtitles', False) or self.params.get('writeautomaticsub')) 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]
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
index 2acaab668..42abb8358 100644
--- a/youtube_dl/__init__.py
+++ b/youtube_dl/__init__.py
@@ -191,6 +191,9 @@ def parseOpts(overrideArguments=None):
video_format.add_option('--write-sub', '--write-srt',
action='store_true', dest='writesubtitles',
help='write subtitle file (currently youtube only)', default=False)
+ video_format.add_option('--write-auto-sub', '--write-automatic-sub',
+ action='store_true', dest='writeautomaticsub',
+ help='write automatic subtitle file (currently youtube only)', default=False)
video_format.add_option('--only-sub',
action='store_true', dest='skip_download',
help='[deprecated] alias of --skip-download', default=False)
@@ -537,6 +540,7 @@ def _real_main(argv=None):
'writeinfojson': opts.writeinfojson,
'writethumbnail': opts.writethumbnail,
'writesubtitles': opts.writesubtitles,
+ 'writeautomaticsub': opts.writeautomaticsub,
'allsubtitles': opts.allsubtitles,
'listsubtitles': opts.listsubtitles,
'subtitlesformat': opts.subtitlesformat,
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index de653cb3d..6728f5418 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -454,14 +454,13 @@ class YoutubeIE(InfoExtractor):
if video_subtitles:
(sub_error, sub_lang, sub) = video_subtitles[0]
if sub_error:
- # We try with the automatic captions
- video_subtitles = self._request_automatic_caption(video_id, video_webpage)
- (sub_error_auto, sub_lang, sub) = video_subtitles[0]
- if sub is not None:
- pass
- else:
- # We report the original error
- self._downloader.report_warning(sub_error)
+ self._downloader.report_warning(sub_error)
+
+ if self._downloader.params.get('writeautomaticsub', False):
+ video_subtitles = self._request_automatic_caption(video_id, video_webpage)
+ (sub_error, sub_lang, sub) = video_subtitles[0]
+ if sub_error:
+ self._downloader.report_warning(sub_error)
if self._downloader.params.get('allsubtitles', False):
video_subtitles = self._extract_all_subtitles(video_id)