]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/sina.py
2 from __future__
import unicode_literals
5 from .common
import InfoExtractor
12 get_element_by_attribute
,
17 class SinaIE(InfoExtractor
):
18 _VALID_URL
= r
'''(?x)https?://(?:.*?\.)?video\.sina\.com\.cn/
20 (?:view/|.*\#)(?P<id>\d+)|
21 .+?/(?P<pseudo_id>[^/?#]+)(?:\.s?html)|
22 # This is used by external sites like Weibo
23 api/sinawebApi/outplay.php/(?P<token>.+?)\.swf
29 'url': 'http://video.sina.com.cn/news/spj/topvideoes20160504/?opsubject_id=top1#250576622',
30 'md5': 'd38433e2fc886007729735650ae4b3e9',
34 'title': '现场:克鲁兹宣布退选 特朗普将稳获提名',
38 'url': 'http://video.sina.com.cn/v/b/101314253-1290078633.html',
42 'title': '军方提高对朝情报监视级别',
44 'skip': 'the page does not exist or has been deleted',
47 'url': 'http://video.sina.com.cn/view/250587748.html',
48 'md5': '3d1807a25c775092aab3bc157fff49b4',
52 'title': '瞬间泪目:8年前汶川地震珍贵视频首曝光',
57 def _real_extract(self
, url
):
58 mobj
= self
._match
_valid
_url
(url
)
60 video_id
= mobj
.group('id')
62 if mobj
.group('token') is not None:
63 # The video id is in the redirected url
64 self
.to_screen('Getting video id')
65 request
= HEADRequest(url
)
66 _
, urlh
= self
._download
_webpage
_handle
(request
, 'NA', False)
67 return self
._real
_extract
(urlh
.geturl())
69 pseudo_id
= mobj
.group('pseudo_id')
70 webpage
= self
._download
_webpage
(url
, pseudo_id
)
71 error
= get_element_by_attribute('class', 'errtitle', webpage
)
73 raise ExtractorError('%s said: %s' % (
74 self
.IE_NAME
, clean_html(error
)), expected
=True)
75 video_id
= self
._search
_regex
(
76 r
"video_id\s*:\s*'(\d+)'", webpage
, 'video id')
78 video_data
= self
._download
_json
(
79 'http://s.video.sina.com.cn/video/h5play',
80 video_id
, query
={'video_id': video_id}
)
81 if video_data
['code'] != 1:
82 raise ExtractorError('%s said: %s' % (
83 self
.IE_NAME
, video_data
['message']), expected
=True)
85 video_data
= video_data
['data']
86 title
= video_data
['title']
87 description
= video_data
.get('description')
89 description
= description
.strip()
91 preference
= qualities(['cif', 'sd', 'hd', 'fhd', 'ffd'])
93 for quality_id
, quality
in video_data
.get('videos', {}).get('mp4', {}
).items():
94 file_api
= quality
.get('file_api')
95 file_id
= quality
.get('file_id')
96 if not file_api
or not file_id
:
99 'format_id': quality_id
,
100 'url': update_url_query(file_api
, {'vid': file_id}
),
101 'quality': preference(quality_id
),
104 self
._sort
_formats
(formats
)
109 'description': description
,
110 'thumbnail': video_data
.get('image'),
111 'duration': int_or_none(video_data
.get('length')),
112 'timestamp': int_or_none(video_data
.get('create_time')),