From 61c2a337d7f87c4a9939d092ad8b21b64a5fc9e9 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 22:21:56 +0100 Subject: [PATCH] replaced "blowfish" with "pycryptodome" for faster decryption --- deemix/api/deezer.py | 12 +++++++----- requirements.txt | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/deemix/api/deezer.py b/deemix/api/deezer.py index 0db3d25..ea809ef 100755 --- a/deemix/api/deezer.py +++ b/deemix/api/deezer.py @@ -2,7 +2,7 @@ import binascii import hashlib -import blowfish +from Crypto.Cipher import Blowfish import pyaes import requests @@ -241,24 +241,26 @@ class Deezer: def decrypt_track(self, track_id, input, output): response = open(input, 'rb') 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 while True: chunk = response.read(2048) if not chunk: break 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) i += 1 def stream_track(self, track_id, url, stream): 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 for chunk in request.iter_content(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) i += 1 diff --git a/requirements.txt b/requirements.txt index 7a4433a..af35906 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pyaes -blowfish +pycryptodome mutagen click requests