[youku] PEP8

This commit is contained in:
Yen Chi Hsuan 2015-06-15 22:41:24 +08:00
parent 8268e94cd4
commit aed473ccf9

View file

@ -11,6 +11,7 @@
bytes_is_str = (bytes == str) # for compatible bytes_is_str = (bytes == str) # for compatible
class YoukuIE(InfoExtractor): class YoukuIE(InfoExtractor):
IE_NAME = 'youku' IE_NAME = 'youku'
_VALID_URL = r'''(?x) _VALID_URL = r'''(?x)
@ -36,7 +37,7 @@ def yk_t(s1, s2):
ls = list(range(256)) ls = list(range(256))
t = 0 t = 0
for i in range(256): for i in range(256):
t = (t + ls[i] + ord(s1[i%len(s1)])) % 256 t = (t + ls[i] + ord(s1[i % len(s1)])) % 256
ls[i], ls[t] = ls[t], ls[i] ls[i], ls[t] = ls[t], ls[i]
s = '' if not bytes_is_str else b'' s = '' if not bytes_is_str else b''
x, y = 0, 0 x, y = 0, 0
@ -45,15 +46,15 @@ def yk_t(s1, s2):
x = (x + ls[y]) % 256 x = (x + ls[y]) % 256
ls[x], ls[y] = ls[y], ls[x] ls[x], ls[y] = ls[y], ls[x]
if isinstance(s2[i], int): if isinstance(s2[i], int):
s += chr(s2[i] ^ ls[(ls[x]+ls[y]) % 256]) s += chr(s2[i] ^ ls[(ls[x] + ls[y]) % 256])
else: else:
s += chr(ord(s2[i]) ^ ls[(ls[x]+ls[y]) % 256]) s += chr(ord(s2[i]) ^ ls[(ls[x] + ls[y]) % 256])
return s return s
sid, token = yk_t( sid, token = yk_t(
'becaf9be', 'becaf9be',
base64.b64decode(bytes(data2['ep'], 'ascii')) \ base64.b64decode(bytes(data2['ep'], 'ascii'))
if not bytes_is_str \ if not bytes_is_str
else base64.b64decode(data2['ep']) else base64.b64decode(data2['ep'])
).split('_') ).split('_')
@ -89,13 +90,13 @@ def generate_ep(format, n):
fileid = get_fileid(format, n) fileid = get_fileid(format, n)
ep_t = yk_t( ep_t = yk_t(
'bf7e5f01', 'bf7e5f01',
bytes('%s_%s_%s' % (sid, fileid, token), 'ascii') \ bytes('%s_%s_%s' % (sid, fileid, token), 'ascii')
if not bytes_is_str \ if not bytes_is_str
else ('%s_%s_%s' % (sid, fileid, token)) else ('%s_%s_%s' % (sid, fileid, token))
) )
ep = base64.b64encode( ep = base64.b64encode(
bytes(ep_t, 'latin') \ bytes(ep_t, 'latin')
if not bytes_is_str \ if not bytes_is_str
else ep_t else ep_t
).decode() ).decode()
return ep return ep
@ -121,7 +122,7 @@ def generate_ep(format, n):
video_url = \ video_url = \
'http://k.youku.com/player/getFlvPath/' + \ 'http://k.youku.com/player/getFlvPath/' + \
'sid/' + sid + \ 'sid/' + sid + \
'_' + str(int(n)+1).zfill(2) + \ '_' + str(int(n) + 1).zfill(2) + \
'/st/' + self.parse_ext_l(format) + \ '/st/' + self.parse_ext_l(format) + \
'/fileid/' + get_fileid(format, n) + '?' + \ '/fileid/' + get_fileid(format, n) + '?' + \
compat_urllib_parse.urlencode(param) compat_urllib_parse.urlencode(param)
@ -132,34 +133,34 @@ def generate_ep(format, n):
def get_hd(self, fm): def get_hd(self, fm):
hd_id_dict = { hd_id_dict = {
'flv' : '0', 'flv': '0',
'mp4' : '1', 'mp4': '1',
'hd2' : '2', 'hd2': '2',
'hd3' : '3', 'hd3': '3',
'3gp' : '0', '3gp': '0',
'3gphd' : '1' '3gphd': '1'
} }
return hd_id_dict[fm] return hd_id_dict[fm]
def parse_ext_l(self, fm): def parse_ext_l(self, fm):
ext_dict = { ext_dict = {
'flv' : 'flv', 'flv': 'flv',
'mp4' : 'mp4', 'mp4': 'mp4',
'hd2' : 'flv', 'hd2': 'flv',
'hd3' : 'flv', 'hd3': 'flv',
'3gp' : 'flv', '3gp': 'flv',
'3gphd' : 'mp4' '3gphd': 'mp4'
} }
return ext_dict[fm] return ext_dict[fm]
def get_format_name(self, fm): def get_format_name(self, fm):
_dict = { _dict = {
'3gp' : 'h6', '3gp': 'h6',
'3gphd' : 'h5', '3gphd': 'h5',
'flv' : 'h4', 'flv': 'h4',
'mp4' : 'h3', 'mp4': 'h3',
'hd2' : 'h2', 'hd2': 'h2',
'hd3' : 'h1' 'hd3': 'h1'
} }
return _dict[fm] return _dict[fm]
@ -194,10 +195,9 @@ def _real_extract(self, url):
# construct info # construct info
entries = [] entries = []
for fm in data1['streamtypes']: for fm in data1['streamtypes']:
#formats = []
video_urls = video_urls_dict[fm] video_urls = video_urls_dict[fm]
for i in range(len(video_urls)): for i in range(len(video_urls)):
if len(entries) < i+1: if len(entries) < i + 1:
entries.append({'formats': []}) entries.append({'formats': []})
entries[i]['formats'].append( entries[i]['formats'].append(
{ {
@ -211,7 +211,7 @@ def _real_extract(self, url):
for i in range(len(entries)): for i in range(len(entries)):
entries[i].update( entries[i].update(
{ {
'id': '_part%d' % (i+1), 'id': '_part%d' % (i + 1),
'title': title, 'title': title,
} }
) )