0
0
Fork 0

[le] extract http formats

main
Remita Amine 2016-07-08 15:35:20 +01:00
parent ae8cb5328d
commit 07d7689f2e
1 changed files with 90 additions and 45 deletions

View File

@ -23,6 +23,7 @@ from ..utils import (
str_or_none, str_or_none,
url_basename, url_basename,
urshift, urshift,
update_url_query,
) )
@ -89,6 +90,10 @@ class LeIE(InfoExtractor):
_loc3_ = self.ror(_loc3_, _loc2_ % 17) _loc3_ = self.ror(_loc3_, _loc2_ % 17)
return _loc3_ return _loc3_
# reversed from http://jstatic.letvcdn.com/sdk/player.js
def get_mms_key(self, time):
return self.ror(time, 8) ^ 185025305
# see M3U8Encryption class in KLetvPlayer.swf # see M3U8Encryption class in KLetvPlayer.swf
@staticmethod @staticmethod
def decrypt_m3u8(encrypted_data): def decrypt_m3u8(encrypted_data):
@ -109,23 +114,7 @@ class LeIE(InfoExtractor):
return bytes(_loc7_) return bytes(_loc7_)
def _real_extract(self, url): def _check_errors(self, play_json):
media_id = self._match_id(url)
page = self._download_webpage(url, media_id)
params = {
'id': media_id,
'platid': 1,
'splatid': 101,
'format': 1,
'tkey': self.calc_time_key(int(time.time())),
'domain': 'www.le.com'
}
play_json = self._download_json(
'http://api.le.com/mms/out/video/playJson',
media_id, 'Downloading playJson data', query=params,
headers=self.geo_verification_headers())
# Check for errors # Check for errors
playstatus = play_json['playstatus'] playstatus = play_json['playstatus']
if playstatus['status'] == 0: if playstatus['status'] == 0:
@ -136,43 +125,99 @@ class LeIE(InfoExtractor):
msg = 'Generic error. flag = %d' % flag msg = 'Generic error. flag = %d' % flag
raise ExtractorError(msg, expected=True) raise ExtractorError(msg, expected=True)
playurl = play_json['playurl'] def _real_extract(self, url):
media_id = self._match_id(url)
page = self._download_webpage(url, media_id)
formats = ['350', '1000', '1300', '720p', '1080p'] play_json_h5 = self._download_json(
dispatch = playurl['dispatch'] 'http://api.le.com/mms/out/video/playJsonH5',
media_id, 'Downloading html5 playJson data', query={
'id': media_id,
'platid': 3,
'splatid': 304,
'format': 1,
'tkey': self.get_mms_key(int(time.time())),
'domain': 'www.le.com',
'tss': 'no',
},
headers=self.geo_verification_headers())
self._check_errors(play_json_h5)
urls = [] play_json_flash = self._download_json(
for format_id in formats: 'http://api.le.com/mms/out/video/playJson',
if format_id in dispatch: media_id, 'Downloading flash playJson data', query={
media_url = playurl['domain'][0] + dispatch[format_id][0] 'id': media_id,
media_url += '&' + compat_urllib_parse_urlencode({ 'platid': 1,
'm3v': 1, 'splatid': 101,
'format': 1,
'tkey': self.calc_time_key(int(time.time())),
'domain': 'www.le.com',
},
headers=self.geo_verification_headers())
self._check_errors(play_json_flash)
def get_h5_urls(media_url, format_id):
location = self._download_json(
media_url, media_id,
'Download JSON metadata for format %s' % format_id, query={
'format': 1, 'format': 1,
'expect': 3, 'expect': 3,
'rateid': format_id, 'tss': 'no',
}) })['location']
nodes_data = self._download_json( return {
media_url, media_id, 'http': update_url_query(location, {'tss': 'no'}),
'Download JSON metadata for format %s' % format_id) 'hls': update_url_query(location, {'tss': 'ios'}),
}
req = self._request_webpage( def get_flash_urls(media_url, format_id):
nodes_data['nodelist'][0]['location'], media_id, media_url += '&' + compat_urllib_parse_urlencode({
note='Downloading m3u8 information for format %s' % format_id) 'm3v': 1,
'format': 1,
'expect': 3,
'rateid': format_id,
})
m3u8_data = self.decrypt_m3u8(req.read()) nodes_data = self._download_json(
media_url, media_id,
'Download JSON metadata for format %s' % format_id)
url_info_dict = { req = self._request_webpage(
'url': encode_data_uri(m3u8_data, 'application/vnd.apple.mpegurl'), nodes_data['nodelist'][0]['location'], media_id,
'ext': determine_ext(dispatch[format_id][1]), note='Downloading m3u8 information for format %s' % format_id)
'format_id': format_id,
'protocol': 'm3u8',
}
if format_id[-1:] == 'p': m3u8_data = self.decrypt_m3u8(req.read())
url_info_dict['height'] = int_or_none(format_id[:-1])
urls.append(url_info_dict) return {
'hls': encode_data_uri(m3u8_data, 'application/vnd.apple.mpegurl'),
}
extracted_formats = []
formats = []
for play_json, get_urls in ((play_json_h5, get_h5_urls), (play_json_flash, get_flash_urls)):
playurl = play_json['playurl']
play_domain = playurl['domain'][0]
for format_id, format_data in playurl.get('dispatch', []).items():
if format_id in extracted_formats:
continue
extracted_formats.append(format_id)
media_url = play_domain + format_data[0]
for protocol, format_url in get_urls(media_url, format_id).items():
f = {
'url': format_url,
'ext': determine_ext(format_data[1]),
'format_id': '%s-%s' % (protocol, format_id),
'protocol': 'm3u8_native' if protocol == 'hls' else 'http',
'quality': int_or_none(format_id),
}
if format_id[-1:] == 'p':
f['height'] = int_or_none(format_id[:-1])
formats.append(f)
self._sort_formats(formats, ('height', 'quality', 'format_id'))
publish_time = parse_iso8601(self._html_search_regex( publish_time = parse_iso8601(self._html_search_regex(
r'发布时间&nbsp;([^<>]+) ', page, 'publish time', default=None), r'发布时间&nbsp;([^<>]+) ', page, 'publish time', default=None),
@ -181,7 +226,7 @@ class LeIE(InfoExtractor):
return { return {
'id': media_id, 'id': media_id,
'formats': urls, 'formats': formats,
'title': playurl['title'], 'title': playurl['title'],
'thumbnail': playurl['pic'], 'thumbnail': playurl['pic'],
'description': description, 'description': description,