Add WeiboIE (closes #1039)
[youtube-dl] / youtube_dl / extractor / weibo.py
1 # coding: utf-8
2
3 import re
4
5 from .common import InfoExtractor
6
7 class WeiboIE(InfoExtractor):
8     """
9     The videos in Weibo come from different sites, this IE just finds the link
10     to the external video and returns it.
11     """
12     _VALID_URL = r'https?://video\.weibo\.com/v/weishipin/t_(?P<id>.+?)\.htm'
13
14     _TEST = {
15         u'url': u'http://video.weibo.com/v/weishipin/t_zjUw2kZ.htm',
16         u'file': u'98322879.flv',
17         u'info_dict': {
18             u'title': u'魔声耳机最新广告“All Eyes On Us”',
19         },
20         u'note': u'Sina video',
21         u'params': {
22             u'skip_download': True,
23         },
24     }
25
26     # Additional example videos from different sites
27     # Youku: http://video.weibo.com/v/weishipin/t_zQGDWQ8.htm
28     # 56.com: http://video.weibo.com/v/weishipin/t_zQ44HxN.htm
29
30     def _real_extract(self, url):
31         mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
32         video_id = mobj.group('id')
33         webpage = self._download_webpage(url, video_id)
34         player_url = self._search_regex(r'var defaultPlayer="(.+?)"', webpage,
35                                         u'player url')
36         return self.url_result(player_url)
37