X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=youtube_dl%2Fextractor%2Ftudou.py;h=68712cb4adec484df73d53a21b2ad397335371bd;hb=d434ca5448b62568e6c56c2e9ea83d10c9da196d;hp=dcd823d0838dca23b27298cbf05ad47cc4261637;hpb=9b583dca4cf3b623323de8fadf6dc851b7111fd2;p=youtube-dl diff --git a/youtube_dl/extractor/tudou.py b/youtube_dl/extractor/tudou.py index dcd823d08..68712cb4a 100644 --- a/youtube_dl/extractor/tudou.py +++ b/youtube_dl/extractor/tudou.py @@ -9,7 +9,7 @@ from .common import InfoExtractor class TudouIE(InfoExtractor): - _VALID_URL = r'(?:http://)?(?:www\.)?tudou\.com/(?:listplay|programs|albumplay)/(?:view|(.+?))/(?:([^/]+)|([^/]+))(?:\.html)?' + _VALID_URL = r'https?://(?:www\.)?tudou\.com/(?:listplay|programs(?:/view)?|albumplay)/([^/]+/)*(?P[^/?#]+?)(?:\.html)?/?(?:$|[?#])' _TESTS = [{ 'url': 'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html', 'md5': '140a49ed444bd22f93330985d8475fcb', @@ -28,25 +28,22 @@ class TudouIE(InfoExtractor): 'thumbnail': 're:^https?://.*\.jpg$', } }, { - 'url': 'http://www.tudou.com/albumplay/TenTw_JgiPM/PzsAs5usU9A.html', - 'info_dict': { - 'title': 'todo.mp4', - }, - 'add_ie': ['Youku'], - 'skip': 'Only works from China' + 'url': 'http://www.tudou.com/albumplay/cJAHGih4yYg.html', + 'only_matching': True, }] - def _url_for_id(self, id, quality = None): - info_url = "http://v2.tudou.com/f?id="+str(id) + _PLAYER_URL = 'http://js.tudouui.com/bin/lingtong/PortalPlayer_177.swf' + + def _url_for_id(self, id, quality=None): + info_url = "http://v2.tudou.com/f?id=" + str(id) if quality: info_url += '&hd' + quality webpage = self._download_webpage(info_url, id, "Opening the info webpage") - final_url = self._html_search_regex('>(.+?)',webpage, 'video url') + final_url = self._html_search_regex('>(.+?)', webpage, 'video url') return final_url def _real_extract(self, url): - mobj = re.match(self._VALID_URL, url) - video_id = mobj.group(2) + video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) m = re.search(r'vcode:\s*[\'"](.+?)[\'"]', webpage) @@ -62,6 +59,10 @@ class TudouIE(InfoExtractor): thumbnail_url = self._search_regex( r",pic:\s*[\"'](.+?)[\"']", webpage, 'thumbnail URL', fatal=False) + player_url = self._search_regex( + r"playerUrl\s*:\s*['\"](.+?\.swf)[\"']", + webpage, 'player URL', default=self._PLAYER_URL) + segs_json = self._search_regex(r'segs: \'(.*)\'', webpage, 'segments') segments = json.loads(segs_json) # It looks like the keys are the arguments that have to be passed as @@ -73,7 +74,7 @@ class TudouIE(InfoExtractor): result = [] len_parts = len(parts) if len_parts > 1: - self.to_screen(u'%s: found %s parts' % (video_id, len_parts)) + self.to_screen('%s: found %s parts' % (video_id, len_parts)) for part in parts: part_id = part['k'] final_url = self._url_for_id(part_id, quality) @@ -84,7 +85,15 @@ class TudouIE(InfoExtractor): 'ext': ext, 'title': title, 'thumbnail': thumbnail_url, + 'http_headers': { + 'Referer': player_url, + }, } result.append(part_info) - return result + return { + '_type': 'multi_video', + 'entries': result, + 'id': video_id, + 'title': title, + }