]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/sina.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
13 class SinaIE(InfoExtractor
):
14 _VALID_URL
= r
'''https?://(.*?\.)?video\.sina\.com\.cn/
16 (.+?/(((?P<pseudo_id>\d+).html)|(.*?(\#|(vid=)|b/)(?P<id>\d+?)($|&|\-))))
18 # This is used by external sites like Weibo
19 (api/sinawebApi/outplay.php/(?P<token>.+?)\.swf)
25 'url': 'http://video.sina.com.cn/news/vlist/zt/chczlj2013/?opsubject_id=top12#110028898',
26 'file': '110028898.flv',
27 'md5': 'd65dd22ddcf44e38ce2bf58a10c3e71f',
29 'title': '《中国新闻》 朝鲜要求巴拿马立即释放被扣船员',
33 'url': 'http://video.sina.com.cn/v/b/101314253-1290078633.html',
37 'title': '军方提高对朝情报监视级别',
43 def suitable(cls
, url
):
44 return re
.match(cls
._VALID
_URL
, url
, flags
=re
.VERBOSE
) is not None
46 def _extract_video(self
, video_id
):
47 data
= compat_urllib_parse
.urlencode({'vid': video_id
})
48 url_doc
= self
._download
_xml
('http://v.iask.com/v_play.php?%s' % data
,
49 video_id
, 'Downloading video url')
50 image_page
= self
._download
_webpage
(
51 'http://interface.video.sina.com.cn/interface/common/getVideoImage.php?%s' % data
,
52 video_id
, 'Downloading thumbnail info')
54 return {'id': video_id
,
55 'url': url_doc
.find('./durl/url').text
,
57 'title': url_doc
.find('./vname').text
,
58 'thumbnail': image_page
.split('=')[1],
61 def _real_extract(self
, url
):
62 mobj
= re
.match(self
._VALID
_URL
, url
, flags
=re
.VERBOSE
)
63 video_id
= mobj
.group('id')
64 if mobj
.group('token') is not None:
65 # The video id is in the redirected url
66 self
.to_screen('Getting video id')
67 request
= compat_urllib_request
.Request(url
)
68 request
.get_method
= lambda: 'HEAD'
69 (_
, urlh
) = self
._download
_webpage
_handle
(request
, 'NA', False)
70 return self
._real
_extract
(urlh
.geturl())
71 elif video_id
is None:
72 pseudo_id
= mobj
.group('pseudo_id')
73 webpage
= self
._download
_webpage
(url
, pseudo_id
)
74 video_id
= self
._search
_regex
(r
'vid:\'(\d
+?
)\'', webpage, 'video
id')
76 return self._extract_video(video_id)