]>
Commit | Line | Data |
---|---|---|
24a267b5 JMF |
1 | # coding: utf-8 |
2 | ||
9caa687d | 3 | import re |
24a267b5 | 4 | import json |
9caa687d YK |
5 | |
6 | from .common import InfoExtractor | |
7 | ||
8 | ||
9 | class TudouIE(InfoExtractor): | |
24a267b5 | 10 | _VALID_URL = r'(?:http://)?(?:www\.)?tudou\.com/(?:listplay|programs)/(?:view|(.+?))/(?:([^/]+)|([^/]+))(?:\.html)?' |
6f5ac90c PH |
11 | _TEST = { |
12 | u'url': u'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html', | |
24a267b5 JMF |
13 | u'file': u'159448201.f4v', |
14 | u'md5': u'140a49ed444bd22f93330985d8475fcb', | |
6f5ac90c | 15 | u'info_dict': { |
24a267b5 | 16 | u"title": u"卡马乔国足开大脚长传冲吊集锦" |
6f5ac90c PH |
17 | } |
18 | } | |
9caa687d | 19 | |
24a267b5 JMF |
20 | def _url_for_id(self, id, quality = None): |
21 | info_url = "http://v2.tudou.com/f?id="+str(id) | |
22 | if quality: | |
23 | info_url += '&hd' + quality | |
24 | webpage = self._download_webpage(info_url, id, "Opening the info webpage") | |
25 | final_url = self._html_search_regex('>(.+?)</f>',webpage, 'video url') | |
26 | return final_url | |
27 | ||
9caa687d YK |
28 | def _real_extract(self, url): |
29 | mobj = re.match(self._VALID_URL, url) | |
24a267b5 | 30 | video_id = mobj.group(2) |
9caa687d | 31 | webpage = self._download_webpage(url, video_id) |
9caa687d YK |
32 | title = re.search(",kw:\"(.+)\"",webpage) |
33 | if title is None: | |
34 | title = re.search(",kw: \'(.+)\'",webpage) | |
35 | title = title.group(1) | |
36 | thumbnail_url = re.search(",pic: \'(.+?)\'",webpage) | |
37 | if thumbnail_url is None: | |
38 | thumbnail_url = re.search(",pic:\"(.+?)\"",webpage) | |
39 | thumbnail_url = thumbnail_url.group(1) | |
24a267b5 JMF |
40 | |
41 | segs_json = self._search_regex(r'segs: \'(.*)\'', webpage, 'segments') | |
42 | segments = json.loads(segs_json) | |
43 | # It looks like the keys are the arguments that have to be passed as | |
44 | # the hd field in the request url, we pick the higher | |
45 | quality = sorted(segments.keys())[-1] | |
46 | parts = segments[quality] | |
47 | result = [] | |
48 | len_parts = len(parts) | |
49 | if len_parts > 1: | |
50 | self.to_screen(u'%s: found %s parts' % (video_id, len_parts)) | |
51 | for part in parts: | |
52 | part_id = part['k'] | |
53 | final_url = self._url_for_id(part_id, quality) | |
54 | ext = (final_url.split('?')[0]).split('.')[-1] | |
55 | part_info = {'id': part_id, | |
56 | 'url': final_url, | |
57 | 'ext': ext, | |
58 | 'title': title, | |
59 | 'thumbnail': thumbnail_url, | |
60 | } | |
61 | result.append(part_info) | |
62 | ||
63 | return result |