1
0
Fork 0
mirror of https://codeberg.org/polarisfm/youtube-dl.git synced 2024-12-26 09:36:46 +00:00

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