From 7461ed235985c4256a5f15a4ea17c19993845603 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sun, 20 Sep 2020 11:29:18 +0200 Subject: [PATCH] Added logging alert for bitrate fallback Added 'bitrateFallback' and 'searchFallback' emits for queueUpdate This adds #57 --- deemix/app/downloadjob.py | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index b4ae2ac..8f8cd6d 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -241,6 +241,16 @@ class DownloadJob: newTrack = self.dz.get_track_gw(searchedId) track.parseEssentialData(self.dz, newTrack) track.searched = True + if self.interface: + self.interface.send('queueUpdate', { + 'uuid': self.queueItem.uuid, + 'searchFallback': True, + 'data': { + 'id': track.id, + 'title': track.title, + 'artist': track.mainArtist['name'] + }, + }) return self.download(trackAPI_gw, track) else: raise DownloadFailed("notEncodedNoAlternative") @@ -261,6 +271,16 @@ class DownloadJob: newTrack = self.dz.get_track_gw(searchedId) track.parseEssentialData(self.dz, newTrack) track.searched = True + if self.interface: + self.interface.send('queueUpdate', { + 'uuid': self.queueItem.uuid, + 'searchFallback': True, + 'data': { + 'id': track.id, + 'title': track.title, + 'artist': track.mainArtist['name'] + }, + }) return self.download(trackAPI_gw, track) else: raise DownloadFailed("wrongBitrateNoAlternative") @@ -475,6 +495,16 @@ class DownloadJob: newTrack = self.dz.get_track_gw(searchedId) track.parseEssentialData(self.dz, newTrack) track.searched = True + if self.interface: + self.interface.send('queueUpdate', { + 'uuid': self.queueItem.uuid, + 'searchFallback': True, + 'data': { + 'id': track.id, + 'title': track.title, + 'artist': track.mainArtist['name'] + }, + }) return False else: raise DownloadFailed("notAvailableNoAlternative") @@ -541,6 +571,7 @@ class DownloadJob: return 0 fallback = self.settings['fallbackBitrate'] + falledBack = False formats_non_360 = { 9: "FLAC", @@ -577,6 +608,19 @@ class DownloadJob: except request_exception.HTTPError: # if the format is not available, Deezer returns a 403 error pass if fallback: + if not falledBack: + falledBack = True + logger.info(f"[{track.mainArtist['name']} - {track.title}] Fallback to lower bitrate") + if self.interface: + self.interface.send('queueUpdate', { + 'uuid': self.queueItem.uuid, + 'bitrateFallback': True, + 'data': { + 'id': track.id, + 'title': track.title, + 'artist': track.mainArtist['name'] + }, + }) continue else: return error_num