From e8357cf5e193442a13e1cc65b1c175501332c5aa Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sun, 16 Aug 2020 12:29:51 +0200 Subject: [PATCH] Fixed issues with spotify playlist and the queue manager --- deemix/__init__.py | 2 +- deemix/app/downloadjob.py | 4 ++-- deemix/app/queuemanager.py | 15 ++++++--------- deemix/app/spotifyhelper.py | 6 +++--- setup.py | 2 +- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/deemix/__init__.py b/deemix/__init__.py index bfa5d4c..5c792be 100644 --- a/deemix/__init__.py +++ b/deemix/__init__.py @@ -1,3 +1,3 @@ #!/usr/bin/env python3 -__version__ = "1.1.31" +__version__ = "1.2.0" diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index 80dbc25..5dc4ffb 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -92,7 +92,7 @@ class DownloadJob: self.dz = dz self.sp = sp self.interface = interface - if isinstance(queueItem, QIConvertable): + if isinstance(queueItem, QIConvertable) and queueItem.extra: self.sp.convert_spotify_playlist(self.dz, queueItem, interface=self.interface) self.queueItem = queueItem self.settings = queueItem.settings @@ -609,7 +609,7 @@ class DownloadJob: if 'error' in result: self.completeTrackPercentage() self.queueItem.failed += 1 - self.queueItem.errors.append(result['error']['message']) + self.queueItem.errors.append(result['error']) if self.interface: error = result['error'] self.interface.send("updateQueue", { diff --git a/deemix/app/queuemanager.py b/deemix/app/queuemanager.py index 2b48b64..d185e1e 100644 --- a/deemix/app/queuemanager.py +++ b/deemix/app/queuemanager.py @@ -3,11 +3,12 @@ from deemix.app.downloadjob import DownloadJob from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt from deemix.api.deezer import APIError from spotipy.exceptions import SpotifyException -from deemix.app.queueitem import QISingle, QICollection +from deemix.app.queueitem import QISingle, QICollection, QIConvertable import logging import os.path as path import json from os import remove +from time import sleep logging.basicConfig(level=logging.INFO) logger = logging.getLogger('deemix') @@ -304,9 +305,7 @@ class QueueManager: return QueueError(url, "Spotify Features is not setted up correctly.", "spotifyDisabled") try: - playlist = sp.generate_playlist_queueitem(dz, id, settings) - playlist.bitrate = bitrate - return playlist + return sp.generate_playlist_queueitem(dz, id, bitrate, settings) except SpotifyException as e: return QueueError(url, "Wrong URL: "+e.msg[e.msg.find('\n')+2:]) @@ -423,7 +422,6 @@ class QueueManager: queueList[uuid] = self.queueList[uuid].getResettedItem() else: queueList[uuid] = self.queueList[uuid].toDict() - print(self.queueList[uuid].progress) return queueList def slimQueueList(self): @@ -432,14 +430,14 @@ class QueueManager: queueList[uuid] = self.queueList[uuid].getSlimmedItem() return queueList - def loadQueue(self, dz, sp, configFolder, settings, interface=None): + def loadQueue(self, configFolder, settings, interface=None): if path.isfile(path.join(configFolder, 'queue.json')) and not len(self.queue): if interface: interface.send('restoringQueue') with open(path.join(configFolder, 'queue.json'), 'r') as f: qd = json.load(f) remove(path.join(configFolder, 'queue.json')) - self.restoreQueue(qd['queue'], qd['queueComplete'], qd['queueList'], settings, dz, sp, interface) + self.restoreQueue(qd['queue'], qd['queueComplete'], qd['queueList'], settings) if interface: interface.send('init_downloadQueue', { 'queue': self.queue, @@ -447,9 +445,8 @@ class QueueManager: 'queueList': self.slimQueueList(), 'restored': True }) - self.nextItem(dz, sp, interface) - def restoreQueue(self, queue, queueComplete, queueList, settings, dz, sp, interface=None): + def restoreQueue(self, queue, queueComplete, queueList, settings): self.queue = queue self.queueComplete = queueComplete self.queueList = {} diff --git a/deemix/app/spotifyhelper.py b/deemix/app/spotifyhelper.py index ae7cafe..3f31eaf 100644 --- a/deemix/app/spotifyhelper.py +++ b/deemix/app/spotifyhelper.py @@ -183,7 +183,7 @@ class SpotifyHelper: return dz_album - def generate_playlist_queueitem(self, dz, playlist_id, settings): + def generate_playlist_queueitem(self, dz, playlist_id, bitrate, settings): if not self.spotifyEnabled: raise spotifyFeaturesNotEnabled spotify_playlist = self.sp.playlist(playlist_id) @@ -215,7 +215,7 @@ class SpotifyHelper: extra['playlistAPI'] = playlistAPI return QIConvertable( playlist_id, - 0, + bitrate, spotify_playlist['name'], spotify_playlist['owner']['display_name'], cover, @@ -264,7 +264,7 @@ class SpotifyHelper: collection.append(deezerTrack) convertPercentage = (pos / queueItem.size) * 100 - if round(convertPercentage) != lastPercentage and round(convertPercentage) % 2 == 0: + if round(convertPercentage) != lastPercentage and round(convertPercentage) % 5 == 0: lastPercentage = round(convertPercentage) if interface: interface.send("updateQueue", {'uuid': queueItem.uuid, 'conversion': lastPercentage}) diff --git a/setup.py b/setup.py index 5ccb94b..f555f57 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text() setup( name="deemix", - version="1.1.31", + version="1.2.0", description="A barebone deezer downloader library", long_description=README, long_description_content_type="text/markdown",