]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/leeco.py
2 from __future__
import unicode_literals
10 from .common
import InfoExtractor
11 from ..compat
import (
29 class LeIE(InfoExtractor
):
31 _VALID_URL
= r
'http://www\.le\.com/ptv/vplay/(?P<id>\d+)\.html'
33 _URL_TEMPLATE
= 'http://www.le.com/ptv/vplay/%s.html'
36 'url': 'http://www.le.com/ptv/vplay/22005890.html',
37 'md5': 'edadcfe5406976f42f9f266057ee5e40',
41 'title': '第87届奥斯卡颁奖礼完美落幕 《鸟人》成最大赢家',
42 'description': 'md5:a9cb175fd753e2962176b7beca21a47c',
45 'hls_prefer_native': True,
48 'url': 'http://www.le.com/ptv/vplay/1415246.html',
53 'description': 'md5:f88573d9d7225ada1359eaf0dbf8bcda',
56 'hls_prefer_native': True,
59 'note': 'This video is available only in Mainland China, thus a proxy is needed',
60 'url': 'http://www.le.com/ptv/vplay/1118082.html',
61 'md5': '2424c74948a62e5f31988438979c5ad1',
66 'description': 'md5:7506a5eeb1722bb9d4068f85024e3986',
69 'hls_prefer_native': True,
71 'skip': 'Only available in China',
76 return val
>> n
if val
>= 0 else (val
+ 0x100000000) >> n
78 # ror() and calc_time_key() are reversed from a embedded swf file in KLetvPlayer.swf
79 def ror(self
, param1
, param2
):
81 while _loc3_
< param2
:
82 param1
= self
.urshift(param1
, 1) + ((param1
& 1) << 31)
86 def calc_time_key(self
, param1
):
88 _loc3_
= self
.ror(param1
, _loc2_
% 13)
89 _loc3_
= _loc3_ ^ _loc2_
90 _loc3_
= self
.ror(_loc3_
, _loc2_
% 17)
93 # see M3U8Encryption class in KLetvPlayer.swf
95 def decrypt_m3u8(encrypted_data
):
96 if encrypted_data
[:5].decode('utf-8').lower() != 'vc_01':
98 encrypted_data
= encrypted_data
[5:]
100 _loc4_
= bytearray(2 * len(encrypted_data
))
101 for idx
, val
in enumerate(encrypted_data
):
103 _loc4_
[2 * idx
] = b
// 16
104 _loc4_
[2 * idx
+ 1] = b
% 16
105 idx
= len(_loc4_
) - 11
106 _loc4_
= _loc4_
[idx
:] + _loc4_
[:idx
]
107 _loc7_
= bytearray(len(encrypted_data
))
108 for i
in range(len(encrypted_data
)):
109 _loc7_
[i
] = _loc4_
[2 * i
] * 16 + _loc4_
[2 * i
+ 1]
113 def _real_extract(self
, url
):
114 media_id
= self
._match
_id
(url
)
115 page
= self
._download
_webpage
(url
, media_id
)
121 'tkey': self
.calc_time_key(int(time
.time())),
122 'domain': 'www.le.com'
124 play_json_req
= sanitized_Request(
125 'http://api.le.com/mms/out/video/playJson?' + compat_urllib_parse
.urlencode(params
)
127 cn_verification_proxy
= self
._downloader
.params
.get('cn_verification_proxy')
128 if cn_verification_proxy
:
129 play_json_req
.add_header('Ytdl-request-proxy', cn_verification_proxy
)
131 play_json
= self
._download
_json
(
133 media_id
, 'Downloading playJson data')
136 playstatus
= play_json
['playstatus']
137 if playstatus
['status'] == 0:
138 flag
= playstatus
['flag']
140 msg
= 'Country %s auth error' % playstatus
['country']
142 msg
= 'Generic error. flag = %d' % flag
143 raise ExtractorError(msg
, expected
=True)
145 playurl
= play_json
['playurl']
147 formats
= ['350', '1000', '1300', '720p', '1080p']
148 dispatch
= playurl
['dispatch']
151 for format_id
in formats
:
152 if format_id
in dispatch
:
153 media_url
= playurl
['domain'][0] + dispatch
[format_id
][0]
154 media_url
+= '&' + compat_urllib_parse
.urlencode({
161 nodes_data
= self
._download
_json
(
163 'Download JSON metadata for format %s' % format_id
)
165 req
= self
._request
_webpage
(
166 nodes_data
['nodelist'][0]['location'], media_id
,
167 note
='Downloading m3u8 information for format %s' % format_id
)
169 m3u8_data
= self
.decrypt_m3u8(req
.read())
172 'url': encode_data_uri(m3u8_data
, 'application/vnd.apple.mpegurl'),
173 'ext': determine_ext(dispatch
[format_id
][1]),
174 'format_id': format_id
,
178 if format_id
[-1:] == 'p':
179 url_info_dict
['height'] = int_or_none(format_id
[:-1])
181 urls
.append(url_info_dict
)
183 publish_time
= parse_iso8601(self
._html
_search
_regex
(
184 r
'发布时间 ([^<>]+) ', page
, 'publish time', default
=None),
185 delimiter
=' ', timezone
=datetime
.timedelta(hours
=8))
186 description
= self
._html
_search
_meta
('description', page
, fatal
=False)
191 'title': playurl
['title'],
192 'thumbnail': playurl
['pic'],
193 'description': description
,
194 'timestamp': publish_time
,
198 class LePlaylistIE(InfoExtractor
):
199 _VALID_URL
= r
'http://[a-z]+\.le\.com/[a-z]+/(?P<id>[a-z0-9_]+)'
202 'url': 'http://www.le.com/tv/46177.html',
206 'description': 'md5:395666ff41b44080396e59570dbac01c'
210 'url': 'http://tv.le.com/izt/wuzetian/index.html',
214 'description': 'md5:e12499475ab3d50219e5bba00b3cb248'
216 # This playlist contains some extra videos other than the drama itself
217 'playlist_mincount': 96
219 'url': 'http://tv.le.com/pzt/lswjzzjc/index.shtml',
220 # This series is moved to http://www.le.com/tv/10005297.html
221 'only_matching': True,
223 'url': 'http://www.le.com/comic/92063.html',
224 'only_matching': True,
226 'url': 'http://list.le.com/listn/c1009_sc532002_d2_p1_o1.html',
227 'only_matching': True,
231 def suitable(cls
, url
):
232 return False if LeIE
.suitable(url
) else super(LePlaylistIE
, cls
).suitable(url
)
234 def _real_extract(self
, url
):
235 playlist_id
= self
._match
_id
(url
)
236 page
= self
._download
_webpage
(url
, playlist_id
)
238 # Currently old domain names are still used in playlists
239 media_ids
= orderedSet(re
.findall(
240 r
'<a[^>]+href="http://www\.letv\.com/ptv/vplay/(\d+)\.html', page
))
241 entries
= [self
.url_result(LeIE
._URL
_TEMPLATE
% media_id
, ie
='Le')
242 for media_id
in media_ids
]
244 title
= self
._html
_search
_meta
('keywords', page
,
245 fatal
=False).split(',')[0]
246 description
= self
._html
_search
_meta
('description', page
, fatal
=False)
248 return self
.playlist_result(entries
, playlist_id
, playlist_title
=title
,
249 playlist_description
=description
)
252 class LetvCloudIE(InfoExtractor
):
253 # Most of *.letv.com is changed to *.le.com on 2016/01/02
254 # but yuntv.letv.com is kept, so also keep the extractor name
256 _VALID_URL
= r
'https?://yuntv\.letv\.com/bcloud.html\?.+'
259 'url': 'http://yuntv.letv.com/bcloud.html?uu=p7jnfw5hw9&vu=467623dedf',
260 'md5': '26450599afd64c513bc77030ad15db44',
262 'id': 'p7jnfw5hw9_467623dedf',
264 'title': 'Video p7jnfw5hw9_467623dedf',
267 'url': 'http://yuntv.letv.com/bcloud.html?uu=p7jnfw5hw9&vu=ec93197892&pu=2c7cd40209&auto_play=1&gpcflag=1&width=640&height=360',
268 'md5': 'e03d9cc8d9c13191e1caf277e42dbd31',
270 'id': 'p7jnfw5hw9_ec93197892',
272 'title': 'Video p7jnfw5hw9_ec93197892',
275 'url': 'http://yuntv.letv.com/bcloud.html?uu=p7jnfw5hw9&vu=187060b6fd',
276 'md5': 'cb988699a776b22d4a41b9d43acfb3ac',
278 'id': 'p7jnfw5hw9_187060b6fd',
280 'title': 'Video p7jnfw5hw9_187060b6fd',
286 if obj
['cf'] == 'flash':
287 salt
= '2f9d6924b33a165a6d8b5d3d42f4f987'
288 items
= ['cf', 'format', 'ran', 'uu', 'ver', 'vu']
289 elif obj
['cf'] == 'html5':
290 salt
= 'fbeh5player12c43eccf2bec3300344'
291 items
= ['cf', 'ran', 'uu', 'bver', 'vu']
292 input_data
= ''.join([item
+ obj
[item
] for item
in items
]) + salt
293 obj
['sign'] = hashlib
.md5(input_data
.encode('utf-8')).hexdigest()
295 def _get_formats(self
, cf
, uu
, vu
, media_id
):
296 def get_play_json(cf
, timestamp
):
300 'bver': 'firefox44.0',
304 'ran': compat_str(timestamp
),
307 return self
._download
_json
(
308 'http://api.letvcloud.com/gpc.php?' + compat_urllib_parse
.urlencode(data
),
309 media_id
, 'Downloading playJson data for type %s' % cf
)
311 play_json
= get_play_json(cf
, time
.time())
312 # The server time may be different from local time
313 if play_json
.get('code') == 10071:
314 play_json
= get_play_json(cf
, play_json
['timestamp'])
316 if not play_json
.get('data'):
317 if play_json
.get('message'):
318 raise ExtractorError('Letv cloud said: %s' % play_json
['message'], expected
=True)
319 elif play_json
.get('code'):
320 raise ExtractorError('Letv cloud returned error %d' % play_json
['code'], expected
=True)
322 raise ExtractorError('Letv cloud returned an unknwon error')
325 return base64
.b64decode(s
.encode('utf-8')).decode('utf-8')
328 for media
in play_json
['data']['video_info']['media'].values():
329 play_url
= media
['play_url']
330 url
= b64decode(play_url
['main_url'])
331 decoded_url
= b64decode(url_basename(url
))
334 'ext': determine_ext(decoded_url
),
335 'format_id': str_or_none(play_url
.get('vtype')),
336 'format_note': str_or_none(play_url
.get('definition')),
337 'width': int_or_none(play_url
.get('vwidth')),
338 'height': int_or_none(play_url
.get('vheight')),
343 def _real_extract(self
, url
):
344 uu_mobj
= re
.search('uu=([\w]+)', url
)
345 vu_mobj
= re
.search('vu=([\w]+)', url
)
347 if not uu_mobj
or not vu_mobj
:
348 raise ExtractorError('Invalid URL: %s' % url
, expected
=True)
350 uu
= uu_mobj
.group(1)
351 vu
= vu_mobj
.group(1)
352 media_id
= uu
+ '_' + vu
354 formats
= self
._get
_formats
('flash', uu
, vu
, media_id
) + self
._get
_formats
('html5', uu
, vu
, media_id
)
355 self
._sort
_formats
(formats
)
359 'title': 'Video %s' % media_id
,