3 from __future__ import unicode_literals
8 from .common import InfoExtractor
11 class TudouIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?tudou\.com/(?:listplay|programs(?:/view)?|albumplay)/.*?/(?P<id>[^/?#]+?)(?:\.html)?/?(?:$|[?#])'
14 'url': 'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html',
15 'md5': '140a49ed444bd22f93330985d8475fcb',
19 'title': '卡马乔国足开大脚长传冲吊集锦',
20 'thumbnail': 're:^https?://.*\.jpg$',
23 'url': 'http://www.tudou.com/programs/view/ajX3gyhL0pc/',
27 'title': 'La Sylphide-Bolshoi-Ekaterina Krysanova & Vyacheslav Lopatin 2012',
28 'thumbnail': 're:^https?://.*\.jpg$',
32 _PLAYER_URL = 'http://js.tudouui.com/bin/lingtong/PortalPlayer_177.swf'
34 def _url_for_id(self, id, quality=None):
35 info_url = "http://v2.tudou.com/f?id=" + str(id)
37 info_url += '&hd' + quality
38 webpage = self._download_webpage(info_url, id, "Opening the info webpage")
39 final_url = self._html_search_regex('>(.+?)</f>', webpage, 'video url')
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
44 webpage = self._download_webpage(url, video_id)
46 m = re.search(r'vcode:\s*[\'"](.+?)[\'"]', webpage)
50 'url': 'youku:' + m.group(1),
54 title = self._search_regex(
55 r",kw:\s*['\"](.+?)[\"']", webpage, 'title')
56 thumbnail_url = self._search_regex(
57 r",pic:\s*[\"'](.+?)[\"']", webpage, 'thumbnail URL', fatal=False)
59 player_url = self._search_regex(
60 r"playerUrl\s*:\s*['\"](.+?\.swf)[\"']",
61 webpage, 'player URL', default=self._PLAYER_URL)
63 segs_json = self._search_regex(r'segs: \'(.*)\'', webpage, 'segments')
64 segments = json.loads(segs_json)
65 # It looks like the keys are the arguments that have to be passed as
66 # the hd field in the request url, we pick the higher
67 # Also, filter non-number qualities (see issue #3643).
68 quality = sorted(filter(lambda k: k.isdigit(), segments.keys()),
69 key=lambda k: int(k))[-1]
70 parts = segments[quality]
72 len_parts = len(parts)
74 self.to_screen('%s: found %s parts' % (video_id, len_parts))
77 final_url = self._url_for_id(part_id, quality)
78 ext = (final_url.split('?')[0]).split('.')[-1]
84 'thumbnail': thumbnail_url,
86 'Referer': player_url,
89 result.append(part_info)
92 '_type': 'multi_video',