]>
Commit | Line | Data |
---|---|---|
0932300e | 1 | # coding: utf-8 |
76f270a4 | 2 | from __future__ import unicode_literals |
0932300e JMF |
3 | |
4 | import re | |
0932300e JMF |
5 | |
6 | from .common import InfoExtractor | |
15707c7e | 7 | from ..compat import compat_urllib_parse_urlencode |
5c2266df | 8 | from ..utils import sanitized_Request |
0932300e JMF |
9 | |
10 | ||
11 | class SinaIE(InfoExtractor): | |
437cac8c | 12 | _VALID_URL = r'''(?x)https?://(.*?\.)?video\.sina\.com\.cn/ |
0932300e | 13 | ( |
8b769664 | 14 | (.+?/(((?P<pseudo_id>\d+).html)|(.*?(\#|(vid=)|b/)(?P<id>\d+?)($|&|\-)))) |
0932300e JMF |
15 | | |
16 | # This is used by external sites like Weibo | |
17 | (api/sinawebApi/outplay.php/(?P<token>.+?)\.swf) | |
18 | ) | |
19 | ''' | |
20 | ||
8b769664 JMF |
21 | _TESTS = [ |
22 | { | |
23 | 'url': 'http://video.sina.com.cn/news/vlist/zt/chczlj2013/?opsubject_id=top12#110028898', | |
8b769664 JMF |
24 | 'md5': 'd65dd22ddcf44e38ce2bf58a10c3e71f', |
25 | 'info_dict': { | |
437cac8c PH |
26 | 'id': '110028898', |
27 | 'ext': 'flv', | |
8b769664 JMF |
28 | 'title': '《中国新闻》 朝鲜要求巴拿马立即释放被扣船员', |
29 | } | |
30 | }, | |
31 | { | |
32 | 'url': 'http://video.sina.com.cn/v/b/101314253-1290078633.html', | |
33 | 'info_dict': { | |
34 | 'id': '101314253', | |
35 | 'ext': 'flv', | |
36 | 'title': '军方提高对朝情报监视级别', | |
37 | }, | |
38 | }, | |
39 | ] | |
0932300e | 40 | |
0932300e | 41 | def _extract_video(self, video_id): |
15707c7e | 42 | data = compat_urllib_parse_urlencode({'vid': video_id}) |
e26f8712 | 43 | url_doc = self._download_xml('http://v.iask.com/v_play.php?%s' % data, |
9e1a5b84 | 44 | video_id, 'Downloading video url') |
0932300e JMF |
45 | image_page = self._download_webpage( |
46 | 'http://interface.video.sina.com.cn/interface/common/getVideoImage.php?%s' % data, | |
76f270a4 | 47 | video_id, 'Downloading thumbnail info') |
0932300e JMF |
48 | |
49 | return {'id': video_id, | |
50 | 'url': url_doc.find('./durl/url').text, | |
51 | 'ext': 'flv', | |
52 | 'title': url_doc.find('./vname').text, | |
53 | 'thumbnail': image_page.split('=')[1], | |
54 | } | |
55 | ||
56 | def _real_extract(self, url): | |
437cac8c | 57 | mobj = re.match(self._VALID_URL, url) |
0932300e JMF |
58 | video_id = mobj.group('id') |
59 | if mobj.group('token') is not None: | |
60 | # The video id is in the redirected url | |
76f270a4 | 61 | self.to_screen('Getting video id') |
5c2266df | 62 | request = sanitized_Request(url) |
0932300e JMF |
63 | request.get_method = lambda: 'HEAD' |
64 | (_, urlh) = self._download_webpage_handle(request, 'NA', False) | |
65 | return self._real_extract(urlh.geturl()) | |
66 | elif video_id is None: | |
67 | pseudo_id = mobj.group('pseudo_id') | |
68 | webpage = self._download_webpage(url, pseudo_id) | |
76f270a4 | 69 | video_id = self._search_regex(r'vid:\'(\d+?)\'', webpage, 'video id') |
0932300e JMF |
70 | |
71 | return self._extract_video(video_id) |