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