From 318ad689ea2875ca510b43c12198049c195ed0a5 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Mon, 1 Mar 2021 19:11:07 +0100 Subject: [PATCH] Made nextitem work on a thread --- deemix/app/downloadjob.py | 3 +-- deemix/app/queuemanager.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index d001b46..d7eb36e 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -117,7 +117,6 @@ class DownloadJob: with ThreadPoolExecutor(self.settings['queueConcurrency']) as executor: for pos, track in enumerate(self.queueItem.collection, start=0): tracks[pos] = executor.submit(self.downloadWrapper, track) - pool.waitall() self.collectionAfterDownload(tracks) if self.interface: if self.queueItem.cancel: @@ -159,7 +158,7 @@ class DownloadJob: searched = "" for i in range(len(tracks)): - result = tracks[i].wait() + result = tracks[i].result() if not result: return None # Check if item is cancelled # Log errors to file diff --git a/deemix/app/queuemanager.py b/deemix/app/queuemanager.py index ffbb0a4..8ebcb2f 100644 --- a/deemix/app/queuemanager.py +++ b/deemix/app/queuemanager.py @@ -15,6 +15,8 @@ from os import remove import uuid from urllib.request import urlopen +import threading + logging.basicConfig(level=logging.INFO) logger = logging.getLogger('deemix') @@ -26,6 +28,7 @@ class QueueManager: self.currentItem = "" self.dz = deezerHelper or Deezer() self.sp = spotifyHelper + self.queueThread = None def generateTrackQueueItem(self, id, settings, bitrate, trackAPI=None, albumAPI=None, dz=None): if not dz: dz = self.dz @@ -440,15 +443,18 @@ class QueueManager: if interface: interface.send("addedToQueue", queueItem.getSlimmedItem()) else: return False - self.nextItem(dz, interface) + if not self.queueThread: + self.queueThread = threading.Thread(target=self.nextItem, args=(dz, interface)) + self.queueThread.start() return True def nextItem(self, dz=None, interface=None): if not dz: dz = self.dz # Check that nothing is already downloading and # that the queue is not empty - if self.currentItem != "": return None - if not len(self.queue): return None + if self.currentItem != "" or not len(self.queue): + self.queueThread = None + return None self.currentItem = self.queue.pop(0)