replaced "blowfish" with "pycryptodome" for faster decryption

This commit is contained in:
uh_wot 2020-02-29 22:21:56 +01:00
parent 2d366fdc71
commit 61c2a337d7
2 changed files with 8 additions and 6 deletions

View File

@ -2,7 +2,7 @@
import binascii import binascii
import hashlib import hashlib
import blowfish from Crypto.Cipher import Blowfish
import pyaes import pyaes
import requests import requests
@ -241,24 +241,26 @@ class Deezer:
def decrypt_track(self, track_id, input, output): def decrypt_track(self, track_id, input, output):
response = open(input, 'rb') response = open(input, 'rb')
outfile = open(output, 'wb') outfile = open(output, 'wb')
cipher = blowfish.Cipher(str.encode(self._get_blowfish_key(str(track_id)))) blowfish_key = str.encode(self._get_blowfish_key(str(track_id)))
blowfish = Blowfish.new(blowfish_key, Blowfish.MODE_CBC, b"\x00\x01\x02\x03\x04\x05\x06\x07")
i = 0 i = 0
while True: while True:
chunk = response.read(2048) chunk = response.read(2048)
if not chunk: if not chunk:
break break
if (i % 3) == 0 and len(chunk) == 2048: if (i % 3) == 0 and len(chunk) == 2048:
chunk = b"".join(cipher.decrypt_cbc(chunk, b"\x00\x01\x02\x03\x04\x05\x06\x07")) chunk = blowfish.decrypt(chunk)
outfile.write(chunk) outfile.write(chunk)
i += 1 i += 1
def stream_track(self, track_id, url, stream): def stream_track(self, track_id, url, stream):
request = requests.get(url, stream=True) request = requests.get(url, stream=True)
cipher = blowfish.Cipher(str.encode(self._get_blowfish_key(str(track_id)))) blowfish_key = str.encode(self._get_blowfish_key(str(track_id)))
blowfish = Blowfish.new(blowfish_key, Blowfish.MODE_CBC, b"\x00\x01\x02\x03\x04\x05\x06\x07")
i = 0 i = 0
for chunk in request.iter_content(2048): for chunk in request.iter_content(2048):
if (i % 3) == 0 and len(chunk) == 2048: if (i % 3) == 0 and len(chunk) == 2048:
chunk = b"".join(cipher.decrypt_cbc(chunk, b"\x00\x01\x02\x03\x04\x05\x06\x07")) chunk = blowfish.decrypt(chunk)
stream.write(chunk) stream.write(chunk)
i += 1 i += 1

View File

@ -1,5 +1,5 @@
pyaes pyaes
blowfish pycryptodome
mutagen mutagen
click click
requests requests