aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2015-07-10 18:43:38 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2015-07-10 18:43:38 +0800
commit397a8ea96e228f918f127313f837f7de7dd78aed (patch)
treeae0020aab5468e57a9ab15f513b5b42694eb9771
parent15830339eff9076b1c4ca2cb6322fc1ec55233a8 (diff)
[neteasemusic] Encoding fixes for Python 2.6 and 3.x
-rw-r--r--youtube_dl/extractor/neteasemusic.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/youtube_dl/extractor/neteasemusic.py b/youtube_dl/extractor/neteasemusic.py
index e73c77f89..9e99ddbda 100644
--- a/youtube_dl/extractor/neteasemusic.py
+++ b/youtube_dl/extractor/neteasemusic.py
@@ -11,6 +11,7 @@ from .common import InfoExtractor
from ..compat import (
compat_urllib_request,
compat_urllib_parse,
+ compat_str,
)
@@ -21,14 +22,14 @@ class NetEaseMusicBaseIE(InfoExtractor):
@classmethod
def _encrypt(cls, dfsid):
- salt_bytes = bytearray(cls._NETEASE_SALT, 'utf-8')
- string_bytes = bytearray(str(dfsid))
+ salt_bytes = bytearray(cls._NETEASE_SALT.encode('utf-8'))
+ string_bytes = bytearray(compat_str(dfsid).encode('ascii'))
salt_len = len(salt_bytes)
for i in range(len(string_bytes)):
string_bytes[i] = string_bytes[i] ^ salt_bytes[i % salt_len]
m = md5()
- m.update(string_bytes)
- result = b64encode(m.digest())
+ m.update(bytes(string_bytes))
+ result = b64encode(m.digest()).decode('ascii')
return result.replace('/', '_').replace('+', '-')
@classmethod