Made nextitem work on a thread

This commit is contained in:
RemixDev 2021-03-01 19:11:07 +01:00
parent 9c49bf5d23
commit 318ad689ea
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
2 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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)