[subtitles] Simplify the extraction of subtitles in subclasses and remove NoAutoSubti...
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Wed, 11 Sep 2013 14:05:49 +0000 (16:05 +0200)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Wed, 11 Sep 2013 14:05:49 +0000 (16:05 +0200)
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 {}.

youtube_dl/extractor/dailymotion.py
youtube_dl/extractor/subtitles.py
youtube_dl/extractor/youtube.py

index d73023b9ed01a2bb90ffd7183cbb78cf56ff666a..abd6a36ee0425d15fa5254298a3204f139dea1b4 100644 (file)
@@ -4,7 +4,7 @@ import itertools
 import socket
 
 from .common import InfoExtractor
-from .subtitles import NoAutoSubtitlesInfoExtractor
+from .subtitles import SubtitlesInfoExtractor
 
 from ..utils import (
     compat_http_client,
@@ -18,7 +18,7 @@ from ..utils import (
 )
 
 
-class DailymotionIE(NoAutoSubtitlesInfoExtractor):
+class DailymotionIE(SubtitlesInfoExtractor):
     """Information Extractor for Dailymotion"""
 
     _VALID_URL = r'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/(?:embed/)?video/([^/]+)'
@@ -81,14 +81,7 @@ class DailymotionIE(NoAutoSubtitlesInfoExtractor):
         video_url = info[max_quality]
 
         # subtitles
-        video_subtitles = None
-        video_webpage = 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)
-
+        video_subtitles = self.extract_subtitles(video_id)
         if self._downloader.params.get('listsubtitles', False):
             self._list_available_subtitles(video_id)
             return
index 8953d6789cc186a3b1a5c1756007ee90287a66ac..5ae8b3b167ea9d39055c3c0c0bf37ff954c7d0d1 100644 (file)
@@ -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 {}
index 0476f113e6a25a62f00e5abe4ba493cbc7fe76bf..3bba45b79918dede9ecd1a061ece108cc9728fa4 100644 (file)
@@ -707,12 +707,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
                 video_description = u''
 
         # subtitles
-        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)
+        video_subtitles = self.extract_subtitles(video_id, video_webpage)
 
         if self._downloader.params.get('listsubtitles', False):
             self._list_available_subtitles(video_id)