From 951085f065dc729089d6016ffae72b6a4c3bb049 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 29 Feb 2020 21:57:35 +0100 Subject: [PATCH] Continued replacing urllib with requests --- deemix/app/downloader.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 269583b..7775406 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -257,7 +257,7 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False, extraTrack=None track['selectedFormat'] = format track['selectedFilesize'] = filesize track['album']['bitrate'] = format - track['album']['picUrl'] = "https://e-cdn-images.deezer.com/images/cover/{}/{}x{}-000000-80-0-0.{}".format(track['album']['pic'], settings['embeddedArtworkSize'], settings['embeddedArtworkSize'], 'png' if settings['PNGcovers'] else 'jpg') + track['album']['picUrl'] = "https://e-cdns-images.dzcdn.net/images/cover/{}/{}x{}-000000-80-0-0.{}".format(track['album']['pic'], settings['embeddedArtworkSize'], settings['embeddedArtworkSize'], 'png' if settings['PNGcovers'] else 'jpg') # Generate filename and filepath from metadata filename = generateFilename(track, trackAPI, settings) @@ -282,11 +282,12 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False, extraTrack=None # Save local album art if coverPath: + track['album']['picUrlLocal'] = track['album']['picUrl'].replace(f"{settings['embeddedArtworkSize']}x{settings['embeddedArtworkSize']}", f"{settings['localArtworkSize']}x{settings['localArtworkSize']}") track['album']['picPathLocal'] = os.path.join(coverPath, f"{settingsRegexAlbum(settings['coverImageTemplate'], track['album'], settings)}.{'png' if settings['PNGcovers'] else 'jpg'}") 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']['picUrlLocal']).content) except HTTPError: track['album']['picPathLocal'] = None # Save artist art @@ -296,7 +297,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