3 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_str
15 class TudouIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?tudou\.com/(?:(?:programs|wlplay)/view|(?:listplay|albumplay)/[\w-]{11})/(?P<id>[\w-]{11})'
19 'url': 'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html',
20 'md5': '140a49ed444bd22f93330985d8475fcb',
24 'title': '卡马乔国足开大脚长传冲吊集锦',
25 'thumbnail': 're:^https?://.*\.jpg$',
26 'timestamp': 1372113489000,
27 'description': '卡马乔卡家军,开大脚先进战术不完全集锦!',
33 'url': 'http://www.tudou.com/programs/view/ajX3gyhL0pc/',
37 'title': 'La Sylphide-Bolshoi-Ekaterina Krysanova & Vyacheslav Lopatin 2012',
38 'thumbnail': 're:^https?://.*\.jpg$',
39 'timestamp': 1349207518000,
40 'description': 'md5:294612423894260f2dcd5c6c04fe248b',
47 _PLAYER_URL = 'http://js.tudouui.com/bin/lingtong/PortalPlayer_177.swf'
49 def _url_for_id(self, video_id, quality=None):
50 info_url = 'http://v2.tudou.com/f?id=' + compat_str(video_id)
52 info_url += '&hd' + quality
53 xml_data = self._download_xml(info_url, video_id, 'Opening the info XML page')
54 final_url = xml_data.text
57 def _real_extract(self, url):
58 video_id = self._match_id(url)
59 item_data = self._download_json(
60 'http://www.tudou.com/tvp/getItemInfo.action?ic=%s' % video_id, video_id)
62 youku_vcode = item_data.get('vcode')
64 return self.url_result('youku:' + youku_vcode, ie='Youku')
66 title = unescapeHTML(item_data['kw'])
67 description = item_data.get('desc')
68 thumbnail_url = item_data.get('pic')
69 view_count = int_or_none(item_data.get('playTimes'))
70 timestamp = int_or_none(item_data.get('pt'))
72 segments = self._parse_json(item_data['itemSegs'], video_id)
73 # It looks like the keys are the arguments that have to be passed as
74 # the hd field in the request url, we pick the higher
75 # Also, filter non-number qualities (see issue #3643).
76 quality = sorted(filter(lambda k: k.isdigit(), segments.keys()),
77 key=lambda k: int(k))[-1]
78 parts = segments[quality]
79 len_parts = len(parts)
81 self.to_screen('%s: found %s parts' % (video_id, len_parts))
83 def part_func(partnum):
86 final_url = self._url_for_id(part_id, quality)
87 ext = (final_url.split('?')[0]).split('.')[-1]
93 'thumbnail': thumbnail_url,
94 'description': description,
95 'view_count': view_count,
96 'timestamp': timestamp,
97 'duration': float_or_none(part.get('seconds'), 1000),
98 'filesize': int_or_none(part.get('size')),
100 'Referer': self._PLAYER_URL,
104 entries = InAdvancePagedList(part_func, len_parts, 1)
107 '_type': 'multi_video',
114 class TudouPlaylistIE(InfoExtractor):
115 IE_NAME = 'tudou:playlist'
116 _VALID_URL = r'https?://(?:www\.)?tudou\.com/listplay/(?P<id>[\w-]{11})\.html'
118 'url': 'http://www.tudou.com/listplay/zzdE77v6Mmo.html',
122 'playlist_mincount': 209,
125 def _real_extract(self, url):
126 playlist_id = self._match_id(url)
127 playlist_data = self._download_json(
128 'http://www.tudou.com/tvp/plist.action?lcode=%s' % playlist_id, playlist_id)
129 entries = [self.url_result(
130 'http://www.tudou.com/programs/view/%s' % item['icode'],
131 'Tudou', item['icode'],
132 item['kw']) for item in playlist_data['items']]
133 return self.playlist_result(entries, playlist_id)
136 class TudouAlbumIE(InfoExtractor):
137 IE_NAME = 'tudou:album'
138 _VALID_URL = r'https?://(?:www\.)?tudou\.com/album(?:cover|play)/(?P<id>[\w-]{11})'
140 'url': 'http://www.tudou.com/albumplay/v5qckFJvNJg.html',
144 'playlist_mincount': 45,
147 def _real_extract(self, url):
148 album_id = self._match_id(url)
149 album_data = self._download_json(
150 'http://www.tudou.com/tvp/alist.action?acode=%s' % album_id, album_id)
151 entries = [self.url_result(
152 'http://www.tudou.com/programs/view/%s' % item['icode'],
153 'Tudou', item['icode'],
154 item['kw']) for item in album_data['items']]
155 return self.playlist_result(entries, album_id)