]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[neteasemusic] Encoding fixes for Python 2.6 and 3.x
authorYen Chi Hsuan <yan12125@gmail.com>
Fri, 10 Jul 2015 10:43:38 +0000 (18:43 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Fri, 10 Jul 2015 10:43:38 +0000 (18:43 +0800)
youtube_dl/extractor/neteasemusic.py

index e73c77f89b47f5ac3e9b5b460cb173be3247c86a..9e99ddbdad099d2f4b8427f7b16c2006ac5e5ff3 100644 (file)
@@ -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