From 2dab230a7386780f4beeb642423e31ae8025040d Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 13:35:24 +0200 Subject: [PATCH] Added direct testing fallback for getPreferredBitrate --- deemix/api/deezer.py | 1 + deemix/app/downloadjob.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/deemix/api/deezer.py b/deemix/api/deezer.py index e0e09de..67ab5d2 100755 --- a/deemix/api/deezer.py +++ b/deemix/api/deezer.py @@ -59,6 +59,7 @@ class Deezer: for key, value in response.items(): if key.startswith("FILESIZE_"): filesizes[key] = value + filesizes[key+"_TESTED"] = False return filesizes def gw_api_call(self, method, args=None): diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index c5cea71..0e3c0ad 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -506,6 +506,7 @@ class DownloadJob: logger.warn(f"[{track.mainArtist['name']} - {track.title}] Track not available in FLAC, falling back if necessary") self.removeTrackPercentage() track.filesizes['FILESIZE_FLAC'] = "0" + track.filesizes['FILESIZE_FLAC_TESTED'] = True return self.download(trackAPI_gw, track) if track.searched: result['searched'] = f"{track.mainArtist['name']} - {track.title}" @@ -546,13 +547,20 @@ class DownloadJob: for format_num, format in formats.items(): if format_num <= int(self.bitrate): - if f"FILESIZE_{format}" in track.filesizes and int(track.filesizes[f"FILESIZE_{format}"]) != 0: - return format_num + if f"FILESIZE_{format}" in track.filesizes: + if int(track.filesizes[f"FILESIZE_{format}"]) != 0: + return format_num + elif not track.filesizes[f"FILESIZE_{format}_TESTED"]: + request = get(self.dz.get_track_stream_url(track.id, track.MD5, track.mediaVersion, format_num), stream=True) + try: + request.raise_for_status() + return format_num + except HTTPError: # if the format is not available, Deezer returns a 403 error + pass + if fallback: + continue else: - if fallback: - continue - else: - return error_num + return error_num return error_num # fallback is enabled and loop went through all formats