From f17c302327d20842b0ecf9b064259e522121f662 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Mon, 23 Mar 2020 17:03:04 +0100 Subject: [PATCH 1/4] replaced pyaes and hashlib with pycryptodome equivalents --- deemix/api/deezer.py | 8 ++++---- requirements.txt | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/deemix/api/deezer.py b/deemix/api/deezer.py index e4c9336..862ae58 100755 --- a/deemix/api/deezer.py +++ b/deemix/api/deezer.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import binascii -import hashlib +from Crypto.Hash import MD5 -from Crypto.Cipher import Blowfish +from Crypto.Cipher import Blowfish, AES import pyaes import requests @@ -281,14 +281,14 @@ class Deezer: i += 1 def _md5(self, data): - h = hashlib.new("md5") + h = MD5.new() h.update(str.encode(data) if isinstance(data, str) else data) return h.hexdigest() def _ecb_crypt(self, key, data): res = b'' for x in range(int(len(data) / 16)): - res += binascii.hexlify(pyaes.AESModeOfOperationECB(key).encrypt(data[:16])) + res += binascii.hexlify(AES.new(key, AES.MODE_ECB).encrypt(data[:16])) data = data[16:] return res diff --git a/requirements.txt b/requirements.txt index af35906..1edcf91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -pyaes pycryptodome mutagen click From b922a61e10de554b398691989d6ce49266fd80f0 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Mon, 23 Mar 2020 17:04:58 +0100 Subject: [PATCH 2/4] replaced pycryptodome with pycryptodomex to avoid conflicts with pycrypto --- deemix/api/deezer.py | 4 ++-- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deemix/api/deezer.py b/deemix/api/deezer.py index 862ae58..e1b71c4 100755 --- a/deemix/api/deezer.py +++ b/deemix/api/deezer.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import binascii -from Crypto.Hash import MD5 +from Cryptodome.Hash import MD5 -from Crypto.Cipher import Blowfish, AES +from Cryptodome.Cipher import Blowfish, AES import pyaes import requests diff --git a/requirements.txt b/requirements.txt index 1edcf91..cf8f90a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pycryptodome +pycryptodomex mutagen click requests From 3601ab32ab7ee87dd72dfade89bfe8bcc6e89232 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Mon, 23 Mar 2020 18:03:54 +0100 Subject: [PATCH 3/4] forgot to actually remove pyaes --- deemix/api/deezer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deemix/api/deezer.py b/deemix/api/deezer.py index e1b71c4..b1cff8b 100755 --- a/deemix/api/deezer.py +++ b/deemix/api/deezer.py @@ -3,7 +3,6 @@ import binascii from Cryptodome.Hash import MD5 from Cryptodome.Cipher import Blowfish, AES -import pyaes import requests import time From 4079b2f380e19c9377e28dc4efeb9aea2091c9b1 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Tue, 24 Mar 2020 15:56:28 +0100 Subject: [PATCH 4/4] cleaned up some code --- deemix/api/deezer.py | 46 ++++++++++++----------------------- deemix/utils/pathtemplates.py | 4 +-- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/deemix/api/deezer.py b/deemix/api/deezer.py index b1cff8b..5c68732 100755 --- a/deemix/api/deezer.py +++ b/deemix/api/deezer.py @@ -168,8 +168,7 @@ class Deezer: return tracks_array def get_album_gw(self, alb_id): - body = self.gw_api_call('album.getData', {'alb_id': alb_id}) - return body['results'] + return self.gw_api_call('album.getData', {'alb_id': alb_id})['results'] def get_album_tracks_gw(self, alb_id): tracks_array = [] @@ -181,12 +180,10 @@ class Deezer: return tracks_array def get_artist_gw(self, art_id): - body = self.gw_api_call('deezer.pageArtist', {'art_id': art_id}) - return body + return self.gw_api_call('deezer.pageArtist', {'art_id': art_id}) def get_playlist_gw(self, playlist_id): - body = self.gw_api_call('deezer.pagePlaylist', {'playlist_id': playlist_id}) - return body + return self.gw_api_call('deezer.pagePlaylist', {'playlist_id': playlist_id}) def get_playlist_tracks_gw(self, playlist_id): tracks_array = [] @@ -205,54 +202,43 @@ class Deezer: return tracks_array def get_lyrics_gw(self, sng_id): - body = self.gw_api_call('song.getLyrics', {'sng_id': sng_id}) - return body["results"] + return self.gw_api_call('song.getLyrics', {'sng_id': sng_id})["results"] def get_user_playlist(self, user_id): - body = self.api_call('user/' + str(user_id) + '/playlists', {'limit': -1}) - return body + return self.api_call('user/' + str(user_id) + '/playlists', {'limit': -1}) def get_track(self, user_id): - body = self.api_call('track/' + str(user_id)) - return body + return self.api_call('track/' + str(user_id)) def get_track_by_ISRC(self, isrc): - body = self.api_call('track/isrc:' + isrc) - return body + return self.api_call('track/isrc:' + isrc) def get_charts_top_country(self): return self.get_user_playlist('637006841') def get_playlist(self, playlist_id): - body = self.api_call('playlist/' + str(playlist_id)) - return body + return self.api_call('playlist/' + str(playlist_id)) def get_playlist_tracks(self, playlist_id): - body = self.api_call('playlist/' + str(playlist_id) + '/tracks', {'limit': -1}) - return body + return self.api_call('playlist/' + str(playlist_id) + '/tracks', {'limit': -1}) def get_album(self, album_id): - body = self.api_call('album/' + str(album_id)) - return body + return self.api_call('album/' + str(album_id)) def get_album_by_UPC(self, upc): - body = self.api_call('album/upc:' + str(upc)) + return self.api_call('album/upc:' + str(upc)) def get_album_tracks(self, album_id): - body = self.api_call('album/' + str(album_id) + '/tracks', {'limit': -1}) - return body + return self.api_call('album/' + str(album_id) + '/tracks', {'limit': -1}) def get_artist(self, artist_id): - body = self.api_call('artist/' + str(artist_id)) - return body + return self.api_call('artist/' + str(artist_id)) def get_artist_albums(self, artist_id): - body = self.api_call('artist/' + str(artist_id) + '/albums', {'limit': -1}) - return body + return self.api_call('artist/' + str(artist_id) + '/albums', {'limit': -1}) def search(self, term, search_type, limit=30): - body = self.api_call('search/' + search_type, {'q': term, 'limit': limit}) - return body + return self.api_call('search/' + search_type, {'q': term, 'limit': limit}) def decrypt_track(self, track_id, input, output): response = open(input, 'rb') @@ -286,7 +272,7 @@ class Deezer: def _ecb_crypt(self, key, data): res = b'' - for x in range(int(len(data) / 16)): + for _ in range(int(len(data) / 16)): res += binascii.hexlify(AES.new(key, AES.MODE_ECB).encrypt(data[:16])) data = data[16:] return res diff --git a/deemix/utils/pathtemplates.py b/deemix/utils/pathtemplates.py index c7a21f9..073f5a9 100644 --- a/deemix/utils/pathtemplates.py +++ b/deemix/utils/pathtemplates.py @@ -90,7 +90,7 @@ def generateFilepath(track, trackAPI, settings): (not 'SINGLE_TRACK' in trackAPI or ('SINGLE_TRACK' in trackAPI and settings['createSingleFolder'])) and (not '_EXTRA_PLAYLIST' in trackAPI or ('_EXTRA_PLAYLIST' in trackAPI and settings['savePlaylistAsCompilation']) or ('_EXTRA_PLAYLIST' in trackAPI and settings['createStructurePlaylist'])) )): - filepath += 'CD'+str(track['discNumber']) + pathSep + filepath += 'CD' + str(track['discNumber']) + pathSep return (filepath, artistPath, coverPath, extrasPath) @@ -136,7 +136,7 @@ def settingsRegexAlbum(foldername, album, settings): foldername = foldername.replace("%type%", fixName(album['recordType'], settings['illegalCharacterReplacer'])) foldername = foldername.replace("%upc%", album['barcode']) foldername = foldername.replace("%label%", fixName(album['label'], settings['illegalCharacterReplacer'])) - if len(album['genre'])>0: + if len(album['genre']) > 0: foldername = foldername.replace("%genre%", fixName(album['genre'][0], settings['illegalCharacterReplacer'])) else: foldername = foldername.replace("%genre%", "Unknown")