aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/youku.py
diff options
context:
space:
mode:
authorPeterDing <dfhayst@gmail.com>2015-05-28 21:04:58 +0800
committerPeterDing <dfhayst@gmail.com>2015-05-28 21:04:58 +0800
commitca45246627f5a67a7c82cd40a11e5c4ff5f68871 (patch)
treef36e67edeadb68d3b9b281a0f94f35442c1a28d3 /youtube_dl/extractor/youku.py
parentf9355dc989362f31d8e21ccb8fa765546a2360f2 (diff)
[youku] compatible for python > 3.3 or > 2.7
Diffstat (limited to 'youtube_dl/extractor/youku.py')
-rw-r--r--youtube_dl/extractor/youku.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/youtube_dl/extractor/youku.py b/youtube_dl/extractor/youku.py
index 8d86c3f45..7a07c8a5f 100644
--- a/youtube_dl/extractor/youku.py
+++ b/youtube_dl/extractor/youku.py
@@ -1,6 +1,8 @@
# coding: utf-8
from __future__ import unicode_literals
+import sys
+pyvs = sys.version_info[0]
import re
import base64
@@ -34,16 +36,23 @@ class YoukuIE(InfoExtractor):
for i in range(256):
t = (t + ls[i] + ord(s1[i%len(s1)])) % 256
ls[i], ls[t] = ls[t], ls[i]
- s, x, y = '', 0, 0
+ s = '' if pyvs == 3 else b''
+ x, y = 0, 0
for i in range(len(s2)):
y = (y + 1) % 256
x = (x + ls[y]) % 256
ls[x], ls[y] = ls[y], ls[x]
- s += chr((s2[i] ^ ls[(ls[x]+ls[y]) % 256]))
+ if isinstance(s2[i], int):
+ s += chr(s2[i] ^ ls[(ls[x]+ls[y]) % 256])
+ else:
+ s += chr(ord(s2[i]) ^ ls[(ls[x]+ls[y]) % 256])
return s
sid, token = yk_t(
- 'becaf9be', base64.b64decode(bytes(data2['ep'], 'ascii'))
+ 'becaf9be',
+ base64.b64decode(bytes(data2['ep'], 'ascii')) \
+ if pyvs == 3 \
+ else base64.b64decode(data2['ep'])
).split('_')
# get oip
@@ -78,8 +87,15 @@ class YoukuIE(InfoExtractor):
fileid = get_fileid(format, n)
ep_t = yk_t(
'bf7e5f01',
- bytes('%s_%s_%s' % (sid, fileid, token), 'ascii'))
- ep = base64.b64encode(bytes(ep_t, 'latin')).decode()
+ bytes('%s_%s_%s' % (sid, fileid, token), 'ascii') \
+ if pyvs == 3 \
+ else ('%s_%s_%s' % (sid, fileid, token))
+ )
+ ep = base64.b64encode(
+ bytes(ep_t, 'latin') \
+ if pyvs == 3 \
+ else ep_t
+ ).decode()
ep = ep.replace('+', '%2B')
ep = ep.replace('/', '%2F')
ep = ep.replace('=', '%2D')