]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/youku.py
6 from .common
import InfoExtractor
17 class YoukuIE(InfoExtractor
):
23 (?:v|play(?:er)?)\.(?:youku|tudou)\.com/(?:v_show/id_|player\.php/sid/)|
24 video\.tudou\.com/v/)|
26 (?P<id>[A-Za-z0-9]+)(?:\.html|/v\.swf|)
30 'url': 'http://player.youku.com/player.php/sid/XNDgyMDQ2NTQw/v.swf',
31 'only_matching': True,
33 'url': 'http://v.youku.com/v_show/id_XNjA1NzA2Njgw.html',
34 'note': 'Video protected with password',
36 'id': 'XNjA1NzA2Njgw',
38 'title': '邢義田复旦讲座之想象中的胡人—从“左衽孔子”说起',
40 'thumbnail': r
're:^https?://.*',
41 'uploader': 'FoxJin1006',
42 'uploader_id': '322014285',
43 'uploader_url': 'http://i.youku.com/u/UMTI4ODA1NzE0MA==',
48 'videopassword': '100600',
51 # /play/get.json contains streams with "channel_type":"tail"
52 'url': 'http://v.youku.com/v_show/id_XOTUxMzg4NDMy.html',
54 'id': 'XOTUxMzg4NDMy',
56 'title': '我的世界☆明月庄主☆车震猎杀☆杀人艺术Minecraft',
58 'thumbnail': r
're:^https?://.*',
59 'uploader': '明月庄主moon',
60 'uploader_id': '38465621',
61 'uploader_url': 'https://www.youku.com/profile/index/?uid=UMTUzODYyNDg0',
65 'url': 'https://v.youku.com/v_show/id_XNTA2NTA0MjA1Mg==.html',
67 'id': 'XNTA2NTA0MjA1Mg',
69 'title': 'Minecraft我的世界:建造超大巨型航空飞机,菜鸟vs高手vs黑客',
71 'thumbnail': r
're:^https?://.*',
73 'uploader_id': '156688084',
74 'uploader_url': 'https://www.youku.com/profile/index/?uid=UNjI2NzUyMzM2',
78 'url': 'https://v.youku.com/v_show/id_XNTE1MzczOTg4MA==.html',
80 'id': 'XNTE1MzczOTg4MA',
84 'thumbnail': r
're:^https?://.*',
86 'uploader_id': '1640913339',
87 'uploader_url': 'https://www.youku.com/profile/index/?uid=UNjU2MzY1MzM1Ng==',
91 'url': 'https://play.tudou.com/v_show/id_XNjAxNjI2OTU3Ng==.html?',
93 'id': 'XNjAxNjI2OTU3Ng',
95 'title': '阿斯塔意识到哈里杀了人,自己被骗了',
96 'thumbnail': 'https://m.ykimg.com/0541010164F732752794D4D7B70331D1',
97 'uploader_id': '88758207',
99 'uploader_url': 'https://www.youku.com/profile/index/?uid=UMzU1MDMyODI4',
107 return '%d%s' % (int(time
.time()), ''.join(
108 random
.choices(string
.ascii_letters
, k
=3)))
110 def get_format_name(self
, fm
):
125 def _real_extract(self
, url
):
126 video_id
= self
._match
_id
(url
)
128 self
._set
_cookie
('youku.com', '__ysuid', self
.get_ysuid())
129 self
._set
_cookie
('youku.com', 'xreferrer', 'http://www.youku.com')
131 _
, urlh
= self
._download
_webpage
_handle
(
132 'https://log.mmstat.com/eg.js', video_id
, 'Retrieving cna info')
133 # The etag header is '"foobar"'; let's remove the double quotes
134 cna
= urlh
.headers
['etag'][1:-1]
137 basic_data_params
= {
140 'client_ip': '192.168.1.1',
142 'client_ts': time
.time() / 1000,
145 video_password
= self
.get_param('videopassword')
147 basic_data_params
['password'] = video_password
152 headers
.update(self
.geo_verification_headers())
153 data
= self
._download
_json
(
154 'https://ups.youku.com/ups/get.json', video_id
,
155 'Downloading JSON metadata',
156 query
=basic_data_params
, headers
=headers
)['data']
158 error
= data
.get('error')
160 error_note
= error
.get('note')
161 if error_note
is not None and '因版权原因无法观看此视频' in error_note
:
162 raise ExtractorError(
163 'Youku said: Sorry, this video is available in China only', expected
=True)
164 elif error_note
and '该视频被设为私密' in error_note
:
165 raise ExtractorError(
166 'Youku said: Sorry, this video is private', expected
=True)
168 msg
= 'Youku server reported error %i' % error
.get('code')
169 if error_note
is not None:
170 msg
+= ': ' + clean_html(error_note
)
171 raise ExtractorError(msg
)
174 video_data
= data
['video']
175 title
= video_data
['title']
178 'url': stream
['m3u8_url'],
179 'format_id': self
.get_format_name(stream
.get('stream_type')),
181 'protocol': 'm3u8_native',
182 'filesize': int(stream
.get('size')),
183 'width': stream
.get('width'),
184 'height': stream
.get('height'),
185 } for stream
in data
['stream'] if stream
.get('channel_type') != 'tail']
191 'duration': video_data
.get('seconds'),
192 'thumbnail': video_data
.get('logo'),
193 'uploader': video_data
.get('username'),
194 'uploader_id': str_or_none(video_data
.get('userid')),
195 'uploader_url': data
.get('uploader', {}).get('homepage'),
196 'tags': video_data
.get('tags'),
200 class YoukuShowIE(InfoExtractor
):
201 _VALID_URL
= r
'https?://list\.youku\.com/show/id_(?P<id>[0-9a-z]+)\.html'
202 IE_NAME
= 'youku:show'
205 'url': 'http://list.youku.com/show/id_zc7c670be07ff11e48b3f.html',
207 'id': 'zc7c670be07ff11e48b3f',
209 'description': 'md5:a1ae6f5618571bbeb5c9821f9c81b558',
211 'playlist_count': 50,
213 # Episode number not starting from 1
214 'url': 'http://list.youku.com/show/id_zefbfbd70efbfbd780bef.html',
216 'id': 'zefbfbd70efbfbd780bef',
218 'description': 'md5:275715156abebe5ccc2a1992e9d56b98',
220 'playlist_count': 24,
222 # Ongoing playlist. The initial page is the last one
223 'url': 'http://list.youku.com/show/id_za7c275ecd7b411e1a19e.html',
224 'only_matching': True,
227 'url': 'http://list.youku.com/show/id_zefbfbd61237fefbfbdef.html',
228 'only_matching': True,
230 # Wrong number of reload_id.
231 'url': 'http://list.youku.com/show/id_z20eb4acaf5c211e3b2ad.html',
232 'only_matching': True,
235 def _extract_entries(self
, playlist_data_url
, show_id
, note
, query
):
236 query
['callback'] = 'cb'
237 playlist_data
= self
._download
_json
(
238 playlist_data_url
, show_id
, query
=query
, note
=note
,
239 transform_source
=lambda s
: js_to_json(strip_jsonp(s
))).get('html')
240 if playlist_data
is None:
242 drama_list
= (get_element_by_class('p-drama-grid', playlist_data
)
243 or get_element_by_class('p-drama-half-row', playlist_data
))
244 if drama_list
is None:
245 raise ExtractorError('No episodes found')
246 video_urls
= re
.findall(r
'<a[^>]+href="([^"]+)"', drama_list
)
247 return playlist_data
, [
248 self
.url_result(self
._proto
_relative
_url
(video_url
, 'http:'), YoukuIE
.ie_key())
249 for video_url
in video_urls
]
251 def _real_extract(self
, url
):
252 show_id
= self
._match
_id
(url
)
253 webpage
= self
._download
_webpage
(url
, show_id
)
256 page_config
= self
._parse
_json
(self
._search
_regex
(
257 r
'var\s+PageConfig\s*=\s*({.+});', webpage
, 'page config'),
258 show_id
, transform_source
=js_to_json
)
259 first_page
, initial_entries
= self
._extract
_entries
(
260 'http://list.youku.com/show/module', show_id
,
261 note
='Downloading initial playlist data page',
263 'id': page_config
['showid'],
266 first_page_reload_id
= self
._html
_search
_regex
(
267 r
'<div[^>]+id="(reload_\d+)', first_page
, 'first page reload id')
268 # The first reload_id has the same items as first_page
269 reload_ids
= re
.findall('<li[^>]+data-id="([^"]+)">', first_page
)
270 entries
.extend(initial_entries
)
271 for idx
, reload_id
in enumerate(reload_ids
):
272 if reload_id
== first_page_reload_id
:
274 _
, new_entries
= self
._extract
_entries
(
275 'http://list.youku.com/show/episode', show_id
,
276 note
='Downloading playlist data page %d' % (idx
+ 1),
278 'id': page_config
['showid'],
281 if new_entries
is not None:
282 entries
.extend(new_entries
)
283 desc
= self
._html
_search
_meta
('description', webpage
, fatal
=False)
284 playlist_title
= desc
.split(',')[0] if desc
else None
285 detail_li
= get_element_by_class('p-intro', webpage
)
286 playlist_description
= get_element_by_class(
287 'intro-more', detail_li
) if detail_li
else None
289 return self
.playlist_result(
290 entries
, show_id
, playlist_title
, playlist_description
)