Added an IE for todou
authorM.Yasoob Khalid <yasoob.khld@gmail.com>
Tue, 25 Jun 2013 17:48:08 +0000 (22:48 +0500)
committerM.Yasoob Khalid <yasoob.khld@gmail.com>
Tue, 25 Jun 2013 17:48:08 +0000 (22:48 +0500)
youtube_dl/extractor/__init__.py
youtube_dl/extractor/tudou.py [new file with mode: 0644]

index 7b291f907f79b37ab2a32d9cca6adb2aa4e51749..fdfb1b4eea060eac462a47724d9e0e813ef5f9fb 100644 (file)
@@ -58,6 +58,7 @@ from .youku import YoukuIE
 from .youporn import YouPornIE
 from .youtube import YoutubeIE, YoutubePlaylistIE, YoutubeSearchIE, YoutubeUserIE, YoutubeChannelIE
 from .zdf import ZDFIE
+from .tudou import TudouIE
 
 def gen_extractors():
     """ Return a list of an instance of every supported extractor.
@@ -129,6 +130,7 @@ def gen_extractors():
         BreakIE(),
         VevoIE(),
         JukeboxIE(),
+        TudouIE(),
         GenericIE()
     ]
 
diff --git a/youtube_dl/extractor/tudou.py b/youtube_dl/extractor/tudou.py
new file mode 100644 (file)
index 0000000..9ca860a
--- /dev/null
@@ -0,0 +1,32 @@
+import re
+
+from .common import InfoExtractor
+
+
+class TudouIE(InfoExtractor):
+    _VALID_URL = r'(?:http://)?(?:www\.)?tudou\.com/(?:listplay|programs)/(?:view|(.+?))/(?:([^/]+)|([^/]+)\.html)'
+
+    def _real_extract(self, url):
+        mobj = re.match(self._VALID_URL, url)
+        video_id = mobj.group(2).replace('.html','')
+        webpage = self._download_webpage(url, video_id)
+        video_id = re.search('"k":(.+?),',webpage).group(1)
+        title = re.search(",kw:\"(.+)\"",webpage)
+        if title is None:
+            title = re.search(",kw: \'(.+)\'",webpage)
+        title = title.group(1)
+        thumbnail_url = re.search(",pic: \'(.+?)\'",webpage)
+        if thumbnail_url is None:
+            thumbnail_url = re.search(",pic:\"(.+?)\"",webpage)
+        thumbnail_url = thumbnail_url.group(1)
+        info_url = "http://v2.tudou.com/f?id="+str(video_id)
+        webpage = self._download_webpage(info_url, video_id, "Opening the info webpage")
+        final_url = re.search('\>(.+?)\<\/f\>',webpage).group(1)
+        ext = (final_url.split('?')[0]).split('.')[-1]
+        return [{
+            'id':        video_id,
+            'url':       final_url,
+            'ext':       ext,
+            'title':     title,
+            'thumbnail': thumbnail_url,
+        }]