mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-30 15:10:47 -05:00
[neteasemusic] Encoding fixes for Python 2.6 and 3.x
This commit is contained in:
parent
15830339ef
commit
397a8ea96e
1 changed files with 5 additions and 4 deletions
|
@ -11,6 +11,7 @@
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_urllib_request,
|
compat_urllib_request,
|
||||||
compat_urllib_parse,
|
compat_urllib_parse,
|
||||||
|
compat_str,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,14 +22,14 @@ class NetEaseMusicBaseIE(InfoExtractor):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _encrypt(cls, dfsid):
|
def _encrypt(cls, dfsid):
|
||||||
salt_bytes = bytearray(cls._NETEASE_SALT, 'utf-8')
|
salt_bytes = bytearray(cls._NETEASE_SALT.encode('utf-8'))
|
||||||
string_bytes = bytearray(str(dfsid))
|
string_bytes = bytearray(compat_str(dfsid).encode('ascii'))
|
||||||
salt_len = len(salt_bytes)
|
salt_len = len(salt_bytes)
|
||||||
for i in range(len(string_bytes)):
|
for i in range(len(string_bytes)):
|
||||||
string_bytes[i] = string_bytes[i] ^ salt_bytes[i % salt_len]
|
string_bytes[i] = string_bytes[i] ^ salt_bytes[i % salt_len]
|
||||||
m = md5()
|
m = md5()
|
||||||
m.update(string_bytes)
|
m.update(bytes(string_bytes))
|
||||||
result = b64encode(m.digest())
|
result = b64encode(m.digest()).decode('ascii')
|
||||||
return result.replace('/', '_').replace('+', '-')
|
return result.replace('/', '_').replace('+', '-')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in a new issue