From 15bbb8392baf817a6810a6238a4fc995dd38d25a Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 21:58:10 +0100 Subject: [PATCH 1/4] oops, merged stuff without checking first --- deemix/app/downloader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 269583b..679380c 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -286,7 +286,7 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False, extraTrack=None if not os.path.isfile(track['album']['picPathLocal']): with open(track['album']['picPathLocal'], 'wb') as f: try: - f.write(urlopen(track['album']['picUrl'].replace(f"{settings['embeddedArtworkSize']}x{settings['embeddedArtworkSize']}", f"{settings['localArtworkSize']}x{settings['localArtworkSize']}")).read()) + f.write(get(track['album']['picUrl'].replace(f"{settings['embeddedArtworkSize']}x{settings['embeddedArtworkSize']}", f"{settings['localArtworkSize']}x{settings['localArtworkSize']}")).content) except HTTPError: track['album']['picPathLocal'] = None # Save artist art @@ -296,7 +296,7 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False, extraTrack=None if not os.path.isfile(track['album']['artist']['picPathLocal']): with open(track['album']['artist']['picPathLocal'], 'wb') as f: try: - f.write(urlopen(track['album']['artist']['picUrl']).read()) + f.write(get(track['album']['artist']['picUrl']).content) except HTTPError: track['album']['artist']['picPathLocal'] = None 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 2/4] 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 From 8a6afd969c6b27e7de8a1d10eae6504f8cf6a1c6 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 22:30:12 +0100 Subject: [PATCH 3/4] added multi-threaded downloading --- deemix/app/downloader.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 7775406..4d978c5 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -7,6 +7,7 @@ from os import makedirs from requests import get from requests.exceptions import HTTPError from tempfile import gettempdir +from concurrent.futures import ThreadPoolExecutor dz = Deezer() TEMPDIR = os.path.join(gettempdir(), 'deezloader-imgs') @@ -346,10 +347,11 @@ def download_album(id, settings, overwriteBitrate=False): downloadTrackObj(trackAPI, settings, overwriteBitrate) else: tracksArray = dz.get_album_tracks_gw(id) - for trackAPI in tracksArray: - trackAPI['_EXTRA_ALBUM'] = albumAPI - trackAPI['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate'] - downloadTrackObj(trackAPI, settings, overwriteBitrate) + with ThreadPoolExecutor(settings['queueConcurrency']) as executor: + for trackAPI in tracksArray: + trackAPI['_EXTRA_ALBUM'] = albumAPI + trackAPI['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate'] + executor.submit(downloadTrackObj, trackAPI, settings, overwriteBitrate) def download_playlist(id, settings, overwriteBitrate=False): playlistAPI = dz.get_playlist(id) From 86e17d04d9ca6178e3d4e0b809645fb69ccac7dd Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 22:34:26 +0100 Subject: [PATCH 4/4] forgot playlists --- deemix/app/downloader.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 4d978c5..f985640 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -356,8 +356,9 @@ def download_album(id, settings, overwriteBitrate=False): def download_playlist(id, settings, overwriteBitrate=False): playlistAPI = dz.get_playlist(id) playlistTracksAPI = dz.get_playlist_tracks_gw(id) - for pos, trackAPI in enumerate(playlistTracksAPI, start=1): - trackAPI['_EXTRA_PLAYLIST'] = playlistAPI - trackAPI['POSITION'] = pos - trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate'] - downloadTrackObj(trackAPI, settings, overwriteBitrate) + with ThreadPoolExecutor(settings['queueConcurrency']) as executor: + for pos, trackAPI in enumerate(playlistTracksAPI, start=1): + trackAPI['_EXTRA_PLAYLIST'] = playlistAPI + trackAPI['POSITION'] = pos + trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate'] + executor.submit(downloadTrackObj, trackAPI, settings, overwriteBitrate)