From 97cd903289b5cf23ec6fb7017d2093f8ed6d98ba Mon Sep 17 00:00:00 2001 From: RemixDev Date: Tue, 8 Jun 2021 19:12:15 +0200 Subject: [PATCH] Fixed some issues to make the lib work --- deemix/downloader.py | 18 ++++++++++-------- deemix/settings.py | 6 +++--- deemix/types/DownloadObjects.py | 3 ++- deemix/types/Lyrics.py | 2 +- deemix/utils/pathtemplates.py | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/deemix/downloader.py b/deemix/downloader.py index 58bd12d..22327ab 100644 --- a/deemix/downloader.py +++ b/deemix/downloader.py @@ -154,8 +154,8 @@ class Downloader: if isinstance(self.downloadObject, Single): track = self.downloadWrapper({ 'trackAPI_gw': self.downloadObject.single['trackAPI_gw'], - 'trackAPI': self.downloadObject.single['trackAPI'], - 'albumAPI': self.downloadObject.single['albumAPI'] + 'trackAPI': self.downloadObject.single.get('trackAPI'), + 'albumAPI': self.downloadObject.single.get('albumAPI') }) if track: self.afterDownloadSingle(track) elif isinstance(self.downloadObject, Collection): @@ -164,8 +164,8 @@ class Downloader: for pos, track in enumerate(self.downloadObject.collection['tracks_gw'], start=0): tracks[pos] = executor.submit(self.downloadWrapper, { 'trackAPI_gw': track, - 'albumAPI': self.downloadObject.collection['albumAPI'], - 'playlistAPI': self.downloadObject.collection['playlistAPI'] + 'albumAPI': self.downloadObject.collection.get('albumAPI'), + 'playlistAPI': self.downloadObject.collection.get('playlistAPI') }) self.afterDownloadCollection(tracks) @@ -179,9 +179,9 @@ class Downloader: def download(self, extraData, track=None): returnData = {} trackAPI_gw = extraData['trackAPI_gw'] - trackAPI = extraData['trackAPI'] - albumAPI = extraData['albumAPI'] - playlistAPI = extraData['playlistAPI'] + trackAPI = extraData.get('trackAPI') + albumAPI = extraData.get('albumAPI') + playlistAPI = extraData.get('playlistAPI') if self.downloadObject.isCanceled: raise DownloadCanceled if trackAPI_gw['SNG_ID'] == "0": raise DownloadFailed("notOnDeezer") @@ -327,6 +327,8 @@ class Downloader: try: with open(writepath, 'wb') as stream: streamTrack(stream, track, downloadObject=self.downloadObject, listener=self.listener) + except requests.exceptions.HTTPError as e: + raise DownloadFailed('notAvailable', track) from e except OSError as e: if writepath.is_file(): writepath.unlink() if e.errno == errno.ENOSPC: raise DownloadFailed("noSpaceLeft") from e @@ -386,7 +388,7 @@ class Downloader: if trackAPI_gw.get('VERSION') and trackAPI_gw['VERSION'] not in trackAPI_gw['SNG_TITLE']: tempTrack['title'] += f" {trackAPI_gw['VERSION']}".strip() - itemName = f"[{track.mainArtist.name} - {track.title}]" + itemName = f"[{tempTrack['artist']} - {tempTrack['title']}]" try: result = self.download(extraData, track) diff --git a/deemix/settings.py b/deemix/settings.py index e1298ef..15f15f0 100644 --- a/deemix/settings.py +++ b/deemix/settings.py @@ -20,7 +20,7 @@ class FeaturesOption(): MOVE_TITLE = "2" # Move to track title DEFAULTS = { - "downloadLocation": localpaths.getMusicFolder(), + "downloadLocation": str(localpaths.getMusicFolder()), "tracknameTemplate": "%artist% - %title%", "albumTracknameTemplate": "%tracknumber% - %title%", "playlistTracknameTemplate": "%position% - %artist% - %title%", @@ -122,11 +122,11 @@ def load(configFolder=None): def check(settings): changes = 0 for i_set in DEFAULTS: - if not i_set in settings or not isinstance(settings[i_set], DEFAULTS[i_set]): + if not i_set in settings or not isinstance(settings[i_set], type(DEFAULTS[i_set])): settings[i_set] = DEFAULTS[i_set] changes += 1 for i_set in DEFAULTS['tags']: - if not i_set in settings['tags'] or not isinstance(settings['tags'][i_set], DEFAULTS['tags'][i_set]): + if not i_set in settings['tags'] or not isinstance(settings['tags'][i_set], type(DEFAULTS['tags'][i_set])): settings['tags'][i_set] = DEFAULTS['tags'][i_set] changes += 1 if settings['downloadLocation'] == "": diff --git a/deemix/types/DownloadObjects.py b/deemix/types/DownloadObjects.py index b0c684b..a2f54ac 100644 --- a/deemix/types/DownloadObjects.py +++ b/deemix/types/DownloadObjects.py @@ -8,7 +8,7 @@ class IDownloadObject: self.artist = obj['artist'] self.cover = obj['cover'] self.explicit = obj.get('explicit', False) - self.size = obj['size'] + self.size = obj.get('size', 0) self.downloaded = obj.get('downloaded', 0) self.failed = obj.get('failed', 0) self.progress = obj.get('progress', 0) @@ -16,6 +16,7 @@ class IDownloadObject: self.files = obj.get('files', []) self.progressNext = 0 self.uuid = f"{self.type}_{self.id}_{self.bitrate}" + self.isCanceled = False self.__type__ = None def toDict(self): diff --git a/deemix/types/Lyrics.py b/deemix/types/Lyrics.py index dfb32ef..f16e960 100644 --- a/deemix/types/Lyrics.py +++ b/deemix/types/Lyrics.py @@ -11,7 +11,7 @@ class Lyrics: syncLyricsJson = lyricsAPI["LYRICS_SYNC_JSON"] timestamp = "" milliseconds = 0 - for line in enumerate(syncLyricsJson): + for line, _ in enumerate(syncLyricsJson): if syncLyricsJson[line]["line"] != "": timestamp = syncLyricsJson[line]["lrc_timestamp"] milliseconds = int(syncLyricsJson[line]["milliseconds"]) diff --git a/deemix/utils/pathtemplates.py b/deemix/utils/pathtemplates.py index 32fc69a..b654428 100644 --- a/deemix/utils/pathtemplates.py +++ b/deemix/utils/pathtemplates.py @@ -74,7 +74,7 @@ def generatePath(track, downloadObject, settings): elif downloadObject.type == "album": filenameTemplate = settings['albumTracknameTemplate'] else: - filenameTemplate = settings['plyalistTracknameTemplate'] + filenameTemplate = settings['playlistTracknameTemplate'] filename = generateTrackName(filenameTemplate, track, settings)