aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2013-09-12 11:15:25 +0200
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2013-09-12 11:15:25 +0200
commit6bc520c20706df9e5b32c4d2bccc2d46fb005fc5 (patch)
tree632edfbc89aa01c55e45e856d525350db73aa051
parente3dc22ca3a1790da7a70753ac2c62709d1103175 (diff)
downloadyoutube-dl-6bc520c20706df9e5b32c4d2bccc2d46fb005fc5.tar.xz
Check for both automatic captions and subtitles with options `--write-sub` and `--write-auto-sub` (fixes #1224)
-rw-r--r--youtube_dl/extractor/subtitles.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/youtube_dl/extractor/subtitles.py b/youtube_dl/extractor/subtitles.py
index a95629765..97215f289 100644
--- a/youtube_dl/extractor/subtitles.py
+++ b/youtube_dl/extractor/subtitles.py
@@ -7,6 +7,11 @@ from ..utils import (
class SubtitlesInfoExtractor(InfoExtractor):
+ @property
+ def _have_to_download_any_subtitles(self):
+ return any([self._downloader.params.get('writesubtitles', False),
+ self._downloader.params.get('writeautomaticsub'),
+ self._downloader.params.get('allsubtitles', False)])
def _list_available_subtitles(self, video_id, webpage=None):
""" outputs the available subtitles for the video """
@@ -20,13 +25,17 @@ class SubtitlesInfoExtractor(InfoExtractor):
(video_id, auto_lang))
def extract_subtitles(self, video_id, video_webpage=None):
- """ returns {sub_lang: sub} or {} if subtitles not found """
- if self._downloader.params.get('writesubtitles', False) or self._downloader.params.get('allsubtitles', False):
- available_subs_list = self._get_available_subtitles(video_id)
- elif self._downloader.params.get('writeautomaticsub', False):
- available_subs_list = self._get_available_automatic_caption(video_id, video_webpage)
- else:
+ """
+ returns {sub_lang: sub} ,{} if subtitles not found or None if the
+ subtitles aren't requested.
+ """
+ if not self._have_to_download_any_subtitles:
return None
+ available_subs_list = {}
+ if self._downloader.params.get('writeautomaticsub', False):
+ available_subs_list.update(self._get_available_automatic_caption(video_id, video_webpage))
+ if self._downloader.params.get('writesubtitles', False) or self._downloader.params.get('allsubtitles', False):
+ available_subs_list.update(self._get_available_subtitles(video_id))
if not available_subs_list: # error, it didn't get the available subtitles
return {}