diff options
author | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com> | 2013-09-11 16:05:49 +0200 |
---|---|---|
committer | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com> | 2013-09-11 16:05:49 +0200 |
commit | d82134c3395c0912157c7ccae9f21d4b3375910b (patch) | |
tree | 4a2f24a6cd16b5f4cad1dfd9dfca93c6b5fc010c /youtube_dl/extractor/subtitles.py | |
parent | 54d39d8b2f7a9fe148a24dd2785108b7d3823d9d (diff) |
[subtitles] Simplify the extraction of subtitles in subclasses and remove NoAutoSubtitlesInfoExtractor
Subclasses just need to call the method extract_subtitles, which will call _extract_subtitles and _request_automatic_caption
Now the default implementation of _request_automatic_caption returns {}.
Diffstat (limited to 'youtube_dl/extractor/subtitles.py')
-rw-r--r-- | youtube_dl/extractor/subtitles.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/youtube_dl/extractor/subtitles.py b/youtube_dl/extractor/subtitles.py index 8953d6789..5ae8b3b16 100644 --- a/youtube_dl/extractor/subtitles.py +++ b/youtube_dl/extractor/subtitles.py @@ -62,19 +62,31 @@ class SubtitlesInfoExtractor(InfoExtractor): return sub def _get_available_subtitles(self, video_id): - """ returns {sub_lang: url} or {} if not available """ - """ Must be redefined by the subclasses """ + """ + returns {sub_lang: url} or {} if not available + Must be redefined by the subclasses + """ pass def _request_automatic_caption(self, video_id, webpage): - """ returns {sub_lang: sub} or {} if not available """ - """ Must be redefined by the subclasses """ - pass + """ + returns {sub_lang: sub} or {} if not available + Must be redefined by the subclasses that support automatic captions, + otherwise it will return {} + """ + self._downloader.report_warning(u'Automatic Captions not supported by this server') + return {} + def extract_subtitles(self, video_id, video_webpage=None): + """ + Extract the subtitles and/or the automatic captions if requested. + Returns None or a dictionary in the format {sub_lang: sub} + """ + video_subtitles = None + if self._downloader.params.get('writesubtitles', False) or self._downloader.params.get('allsubtitles', False): + video_subtitles = self._extract_subtitles(video_id) + elif self._downloader.params.get('writeautomaticsub', False): + video_subtitles = self._request_automatic_caption(video_id, video_webpage) + return video_subtitles -class NoAutoSubtitlesInfoExtractor(SubtitlesInfoExtractor): - """ A subtitle class for the servers that don't support auto-captions""" - def _request_automatic_caption(self, video_id, webpage): - self._downloader.report_warning(u'Automatic Captions not supported by this server') - return {} |