]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/youku.py
6 from .common
import InfoExtractor
16 class YoukuIE(InfoExtractor
):
22 (?:v|player)\.youku\.com/(?:v_show/id_|player\.php/sid/)|
23 video\.tudou\.com/v/)|
25 (?P<id>[A-Za-z0-9]+)(?:\.html|/v\.swf|)
30 'url': 'http://v.youku.com/v_show/id_XMTc1ODE5Njcy.html',
32 'id': 'XMTc1ODE5Njcy',
33 'title': '★Smile﹗♡ Git Fresh -Booty Music舞蹈.',
36 'thumbnail': r
're:^https?://.*',
38 'uploader_id': '36017967',
39 'uploader_url': 'http://i.youku.com/u/UMTQ0MDcxODY4',
43 'url': 'http://player.youku.com/player.php/sid/XNDgyMDQ2NTQw/v.swf',
44 'only_matching': True,
46 'url': 'http://v.youku.com/v_show/id_XODgxNjg1Mzk2_ev_1.html',
48 'id': 'XODgxNjg1Mzk2',
52 'thumbnail': r
're:^https?://.*',
54 'uploader_id': '62583473',
55 'uploader_url': 'http://i.youku.com/u/UMjUwMzMzODky',
59 'url': 'http://v.youku.com/v_show/id_XMTI1OTczNDM5Mg==.html',
61 'id': 'XMTI1OTczNDM5Mg',
65 'thumbnail': r
're:^https?://.*',
66 'uploader': '放剧场-花千骨',
67 'uploader_id': '772849359',
68 'uploader_url': 'http://i.youku.com/u/UMzA5MTM5NzQzNg==',
72 'url': 'http://v.youku.com/v_show/id_XNjA1NzA2Njgw.html',
73 'note': 'Video protected with password',
75 'id': 'XNjA1NzA2Njgw',
77 'title': '邢義田复旦讲座之想象中的胡人—从“左衽孔子”说起',
79 'thumbnail': r
're:^https?://.*',
80 'uploader': 'FoxJin1006',
81 'uploader_id': '322014285',
82 'uploader_url': 'http://i.youku.com/u/UMTI4ODA1NzE0MA==',
86 'videopassword': '100600',
89 # /play/get.json contains streams with "channel_type":"tail"
90 'url': 'http://v.youku.com/v_show/id_XOTUxMzg4NDMy.html',
92 'id': 'XOTUxMzg4NDMy',
94 'title': '我的世界☆明月庄主☆车震猎杀☆杀人艺术Minecraft',
96 'thumbnail': r
're:^https?://.*',
97 'uploader': '明月庄主moon',
98 'uploader_id': '38465621',
99 'uploader_url': 'http://i.youku.com/u/UMTUzODYyNDg0',
103 'url': 'http://video.tudou.com/v/XMjIyNzAzMTQ4NA==.html?f=46177805',
105 'id': 'XMjIyNzAzMTQ4NA',
107 'title': '卡马乔国足开大脚长传冲吊集锦',
109 'thumbnail': r
're:^https?://.*',
110 'uploader': '阿卜杜拉之星',
111 'uploader_id': '2382249',
112 'uploader_url': 'http://i.youku.com/u/UOTUyODk5Ng==',
116 'url': 'http://video.tudou.com/v/XMjE4ODI3OTg2MA==.html',
117 'only_matching': True,
122 return '%d%s' % (int(time
.time()), ''.join([
123 random
.choice(string
.ascii_letters
) for i
in range(3)]))
125 def get_format_name(self
, fm
):
140 def _real_extract(self
, url
):
141 video_id
= self
._match
_id
(url
)
143 self
._set
_cookie
('youku.com', '__ysuid', self
.get_ysuid())
144 self
._set
_cookie
('youku.com', 'xreferrer', 'http://www.youku.com')
146 _
, urlh
= self
._download
_webpage
_handle
(
147 'https://log.mmstat.com/eg.js', video_id
, 'Retrieving cna info')
148 # The etag header is '"foobar"'; let's remove the double quotes
149 cna
= urlh
.headers
['etag'][1:-1]
152 basic_data_params
= {
155 'client_ip': '192.168.1.1',
157 'client_ts': time
.time() / 1000,
160 video_password
= self
.get_param('videopassword')
162 basic_data_params
['password'] = video_password
167 headers
.update(self
.geo_verification_headers())
168 data
= self
._download
_json
(
169 'https://ups.youku.com/ups/get.json', video_id
,
170 'Downloading JSON metadata',
171 query
=basic_data_params
, headers
=headers
)['data']
173 error
= data
.get('error')
175 error_note
= error
.get('note')
176 if error_note
is not None and '因版权原因无法观看此视频' in error_note
:
177 raise ExtractorError(
178 'Youku said: Sorry, this video is available in China only', expected
=True)
179 elif error_note
and '该视频被设为私密' in error_note
:
180 raise ExtractorError(
181 'Youku said: Sorry, this video is private', expected
=True)
183 msg
= 'Youku server reported error %i' % error
.get('code')
184 if error_note
is not None:
185 msg
+= ': ' + error_note
186 raise ExtractorError(msg
)
189 video_data
= data
['video']
190 title
= video_data
['title']
193 'url': stream
['m3u8_url'],
194 'format_id': self
.get_format_name(stream
.get('stream_type')),
196 'protocol': 'm3u8_native',
197 'filesize': int(stream
.get('size')),
198 'width': stream
.get('width'),
199 'height': stream
.get('height'),
200 } for stream
in data
['stream'] if stream
.get('channel_type') != 'tail']
206 'duration': video_data
.get('seconds'),
207 'thumbnail': video_data
.get('logo'),
208 'uploader': video_data
.get('username'),
209 'uploader_id': str_or_none(video_data
.get('userid')),
210 'uploader_url': data
.get('uploader', {}).get('homepage'),
211 'tags': video_data
.get('tags'),
215 class YoukuShowIE(InfoExtractor
):
216 _VALID_URL
= r
'https?://list\.youku\.com/show/id_(?P<id>[0-9a-z]+)\.html'
217 IE_NAME
= 'youku:show'
220 'url': 'http://list.youku.com/show/id_zc7c670be07ff11e48b3f.html',
222 'id': 'zc7c670be07ff11e48b3f',
224 'description': 'md5:a1ae6f5618571bbeb5c9821f9c81b558',
226 'playlist_count': 50,
228 # Episode number not starting from 1
229 'url': 'http://list.youku.com/show/id_zefbfbd70efbfbd780bef.html',
231 'id': 'zefbfbd70efbfbd780bef',
233 'description': 'md5:275715156abebe5ccc2a1992e9d56b98',
235 'playlist_count': 24,
237 # Ongoing playlist. The initial page is the last one
238 'url': 'http://list.youku.com/show/id_za7c275ecd7b411e1a19e.html',
239 'only_matching': True,
242 'url': 'http://list.youku.com/show/id_zefbfbd61237fefbfbdef.html',
243 'only_matching': True,
245 # Wrong number of reload_id.
246 'url': 'http://list.youku.com/show/id_z20eb4acaf5c211e3b2ad.html',
247 'only_matching': True,
250 def _extract_entries(self
, playlist_data_url
, show_id
, note
, query
):
251 query
['callback'] = 'cb'
252 playlist_data
= self
._download
_json
(
253 playlist_data_url
, show_id
, query
=query
, note
=note
,
254 transform_source
=lambda s
: js_to_json(strip_jsonp(s
))).get('html')
255 if playlist_data
is None:
257 drama_list
= (get_element_by_class('p-drama-grid', playlist_data
)
258 or get_element_by_class('p-drama-half-row', playlist_data
))
259 if drama_list
is None:
260 raise ExtractorError('No episodes found')
261 video_urls
= re
.findall(r
'<a[^>]+href="([^"]+)"', drama_list
)
262 return playlist_data
, [
263 self
.url_result(self
._proto
_relative
_url
(video_url
, 'http:'), YoukuIE
.ie_key())
264 for video_url
in video_urls
]
266 def _real_extract(self
, url
):
267 show_id
= self
._match
_id
(url
)
268 webpage
= self
._download
_webpage
(url
, show_id
)
271 page_config
= self
._parse
_json
(self
._search
_regex
(
272 r
'var\s+PageConfig\s*=\s*({.+});', webpage
, 'page config'),
273 show_id
, transform_source
=js_to_json
)
274 first_page
, initial_entries
= self
._extract
_entries
(
275 'http://list.youku.com/show/module', show_id
,
276 note
='Downloading initial playlist data page',
278 'id': page_config
['showid'],
281 first_page_reload_id
= self
._html
_search
_regex
(
282 r
'<div[^>]+id="(reload_\d+)', first_page
, 'first page reload id')
283 # The first reload_id has the same items as first_page
284 reload_ids
= re
.findall('<li[^>]+data-id="([^"]+)">', first_page
)
285 entries
.extend(initial_entries
)
286 for idx
, reload_id
in enumerate(reload_ids
):
287 if reload_id
== first_page_reload_id
:
289 _
, new_entries
= self
._extract
_entries
(
290 'http://list.youku.com/show/episode', show_id
,
291 note
='Downloading playlist data page %d' % (idx
+ 1),
293 'id': page_config
['showid'],
296 if new_entries
is not None:
297 entries
.extend(new_entries
)
298 desc
= self
._html
_search
_meta
('description', webpage
, fatal
=False)
299 playlist_title
= desc
.split(',')[0] if desc
else None
300 detail_li
= get_element_by_class('p-intro', webpage
)
301 playlist_description
= get_element_by_class(
302 'intro-more', detail_li
) if detail_li
else None
304 return self
.playlist_result(
305 entries
, show_id
, playlist_title
, playlist_description
)