浏览代码

[subtitles] made inheritance hierarchy flat as requested

Ismael Mejia 12 年之前
父节点
当前提交
f8e52269c1
共有 2 个文件被更改,包括 17 次插入21 次删除
  1. 15 17
      youtube_dl/extractor/dailymotion.py
  2. 2 4
      youtube_dl/extractor/youtube.py

+ 15 - 17
youtube_dl/extractor/dailymotion.py

@@ -18,23 +18,7 @@ from ..utils import (
 )
 )
 
 
 
 
-class DailyMotionSubtitlesIE(NoAutoSubtitlesIE):
-
-    def _get_available_subtitles(self, video_id):
-        request = compat_urllib_request.Request('https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id)
-        try:
-            sub_list = compat_urllib_request.urlopen(request).read().decode('utf-8')
-        except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
-            self._downloader.report_warning(u'unable to download video subtitles: %s' % compat_str(err))
-            return {}
-        info = json.loads(sub_list)
-        if (info['total'] > 0):
-            sub_lang_list = dict((l['language'], l['url']) for l in info['list'])
-            return sub_lang_list
-        self._downloader.report_warning(u'video doesn\'t have subtitles')
-        return {}
-
-class DailymotionIE(DailyMotionSubtitlesIE, InfoExtractor):
+class DailymotionIE(NoAutoSubtitlesIE):
     """Information Extractor for Dailymotion"""
     """Information Extractor for Dailymotion"""
 
 
     _VALID_URL = r'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/(?:embed/)?video/([^/]+)'
     _VALID_URL = r'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/(?:embed/)?video/([^/]+)'
@@ -120,6 +104,20 @@ class DailymotionIE(DailyMotionSubtitlesIE, InfoExtractor):
             'thumbnail': info['thumbnail_url']
             'thumbnail': info['thumbnail_url']
         }]
         }]
 
 
+    def _get_available_subtitles(self, video_id):
+        request = compat_urllib_request.Request('https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id)
+        try:
+            sub_list = compat_urllib_request.urlopen(request).read().decode('utf-8')
+        except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
+            self._downloader.report_warning(u'unable to download video subtitles: %s' % compat_str(err))
+            return {}
+        info = json.loads(sub_list)
+        if (info['total'] > 0):
+            sub_lang_list = dict((l['language'], l['url']) for l in info['list'])
+            return sub_lang_list
+        self._downloader.report_warning(u'video doesn\'t have subtitles')
+        return {}
+
 
 
 class DailymotionPlaylistIE(InfoExtractor):
 class DailymotionPlaylistIE(InfoExtractor):
     _VALID_URL = r'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
     _VALID_URL = r'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'

+ 2 - 4
youtube_dl/extractor/youtube.py

@@ -24,7 +24,7 @@ from ..utils import (
     orderedSet,
     orderedSet,
 )
 )
 
 
-class YoutubeBaseInfoExtractor(InfoExtractor):
+class YoutubeBaseInfoExtractor(SubtitlesIE):
     """Provide base functions for Youtube extractors"""
     """Provide base functions for Youtube extractors"""
     _LOGIN_URL = 'https://accounts.google.com/ServiceLogin'
     _LOGIN_URL = 'https://accounts.google.com/ServiceLogin'
     _LANG_URL = r'https://www.youtube.com/?hl=en&persist_hl=1&gl=US&persist_gl=1&opt_out_ackd=1'
     _LANG_URL = r'https://www.youtube.com/?hl=en&persist_hl=1&gl=US&persist_gl=1&opt_out_ackd=1'
@@ -131,8 +131,6 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
             return
             return
         self._confirm_age()
         self._confirm_age()
 
 
-class YoutubeSubtitlesIE(SubtitlesIE):
-
     def _get_available_subtitles(self, video_id):
     def _get_available_subtitles(self, video_id):
         request = compat_urllib_request.Request('http://video.google.com/timedtext?hl=en&type=list&v=%s' % video_id)
         request = compat_urllib_request.Request('http://video.google.com/timedtext?hl=en&type=list&v=%s' % video_id)
         try:
         try:
@@ -189,7 +187,7 @@ class YoutubeSubtitlesIE(SubtitlesIE):
             self._downloader.report_warning(err_msg)
             self._downloader.report_warning(err_msg)
             return {}
             return {}
 
 
-class YoutubeIE(YoutubeSubtitlesIE, YoutubeBaseInfoExtractor):
+class YoutubeIE(YoutubeBaseInfoExtractor):
     IE_DESC = u'YouTube.com'
     IE_DESC = u'YouTube.com'
     _VALID_URL = r"""^
     _VALID_URL = r"""^
                      (
                      (