]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/weibo.py
update changelog.
[youtubedl] / youtube_dl / extractor / weibo.py
1 # coding: utf-8
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7
8 class WeiboIE(InfoExtractor):
9 """
10 The videos in Weibo come from different sites, this IE just finds the link
11 to the external video and returns it.
12 """
13 _VALID_URL = r'https?://video\.weibo\.com/v/weishipin/t_(?P<id>.+?)\.htm'
14
15 _TEST = {
16 u'url': u'http://video.weibo.com/v/weishipin/t_zjUw2kZ.htm',
17 u'file': u'98322879.flv',
18 u'info_dict': {
19 u'title': u'魔声耳机最新广告“All Eyes On Us”',
20 },
21 u'note': u'Sina video',
22 u'params': {
23 u'skip_download': True,
24 },
25 }
26
27 # Additional example videos from different sites
28 # Youku: http://video.weibo.com/v/weishipin/t_zQGDWQ8.htm
29 # 56.com: http://video.weibo.com/v/weishipin/t_zQ44HxN.htm
30
31 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
33 video_id = mobj.group('id')
34 info_url = 'http://video.weibo.com/?s=v&a=play_list&format=json&mix_video_id=t_%s' % video_id
35 info_page = self._download_webpage(info_url, video_id)
36 info = json.loads(info_page)
37
38 videos_urls = map(lambda v: v['play_page_url'], info['result']['data'])
39 #Prefer sina video since they have thumbnails
40 videos_urls = sorted(videos_urls, key=lambda u: u'video.sina.com' in u)
41 player_url = videos_urls[-1]
42 m_sina = re.match(r'https?://video.sina.com.cn/v/b/(\d+)-\d+.html', player_url)
43 if m_sina is not None:
44 self.to_screen('Sina video detected')
45 sina_id = m_sina.group(1)
46 player_url = 'http://you.video.sina.com.cn/swf/quotePlayer.swf?vid=%s' % sina_id
47 return self.url_result(player_url)
48