From c75e6a8e9e1a0d309d54fcea78c1f31793daf201 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Tue, 14 Apr 2020 16:48:13 +0200 Subject: [PATCH] Added clear and cancel queue buttons --- deemix/app/downloader.py | 2 +- deemix/app/queuemanager.py | 40 ++++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 9741b1d..d5b53b7 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -688,7 +688,7 @@ def after_download(tracks, settings, queueItem): f.write(line+"\n") if settings['executeCommand'] != "": execute(settings['executeCommand'].replace("%folder%", extrasPath)) - return track['extrasPath'] + return extrasPath def after_download_single(track, settings, queueItem): if 'cancel' in track: diff --git a/deemix/app/queuemanager.py b/deemix/app/queuemanager.py index 6cd656c..891d6e6 100644 --- a/deemix/app/queuemanager.py +++ b/deemix/app/queuemanager.py @@ -5,8 +5,8 @@ from deemix.app.downloader import download queue = [] queueList = {} +queueComplete = [] currentItem = "" -currentJob = None """ queueItem base structure @@ -142,7 +142,7 @@ def generateQueueItem(dz, url, settings, bitrate=None, albumAPI=None, socket=Non print("Spotify Features is not setted up correctly.") result['error'] = "Spotify Features is not setted up correctly." elif album_id != 0: - return generateQueueItem(dz, f'https://www.deezer.com/album/{track_id}', settings, bitrate) + return generateQueueItem(dz, f'https://www.deezer.com/album/{album_id}', settings, bitrate) else: print("Album not found on deezer!") result['error'] = "Album not found on deezer!" @@ -152,7 +152,7 @@ def generateQueueItem(dz, url, settings, bitrate=None, albumAPI=None, socket=Non return result def addToQueue(dz, url, settings, bitrate=None, socket=None): - global currentItem, currentJob, queueList, queue + global currentItem, queueList, queue if not dz.logged_in: return "Not logged in" queueItem = generateQueueItem(dz, url, settings, bitrate, socket=socket) @@ -170,23 +170,23 @@ def addToQueue(dz, url, settings, bitrate=None, socket=None): else: if 'error' in queueItem: if socket: - socket.emit("toast", {'msg': queueItem['error']}) + socket.emit("toast", {'msg': queueItem['error'], 'icon': 'error'}) return False if queueItem['uuid'] in list(queueList.keys()): print("Already in queue!") if socket: - socket.emit("toast", {'msg': f"{queueItem['title']} is already in queue!"}) + socket.emit("toast", {'msg': f"{queueItem['title']} is already in queue!", 'icon': 'playlist_add_check'}) return False if socket: socket.emit("addedToQueue", queueItem) - socket.emit("toast", {'msg': f"{queueItem['title']} added to queue"}) + socket.emit("toast", {'msg': f"{queueItem['title']} added to queue", 'icon': 'playlist_add'}) queue.append(queueItem['uuid']) queueList[queueItem['uuid']] = queueItem nextItem(dz, socket) return True def nextItem(dz, socket=None): - global currentItem, currentJob, queueList, queue + global currentItem, queueList, queue if currentItem != "": return None else: @@ -200,15 +200,20 @@ def nextItem(dz, socket=None): callbackQueueDone(result) def callbackQueueDone(result): - global currentItem, currentJob, queueList, queue - del queueList[currentItem] + global currentItem, queueList, queueComplete + if 'cancel' in queueList[currentItem]: + del queueList[currentItem] + else: + queueComplete.append(currentItem) currentItem = "" nextItem(result['dz'], result['socket']) def getQueue(): - return (queue, queueList, currentItem) + global currentItem, queueList, queue, queueComplete + return (queue, queueComplete, queueList, currentItem) def removeFromQueue(uuid, socket=None): + global currentItem, queueList, queue, queueComplete if uuid == currentItem: queueList[uuid]['cancel'] = True elif uuid in queue: @@ -216,9 +221,16 @@ def removeFromQueue(uuid, socket=None): del queueList[uuid] if socket: socket.emit("removedFromQueue", uuid) + elif uuid in queueComplete: + queueComplete.remove(uuid) + del queueList[uuid] + if socket: + socket.emit("removedFromQueue", uuid) def cancelAllDownloads(socket=None): + global currentItem, queueList, queue, queueComplete queue = [] + queueComplete = [] if currentItem != "": queueList[currentItem]['cancel'] = True for uuid in list(queueList.keys()): @@ -226,3 +238,11 @@ def cancelAllDownloads(socket=None): del queueList[uuid] if socket: socket.emit("removedAllDownloads") + +def removeFinishedDownloads(socket=None): + global queueList, queueComplete + for uuid in queueComplete: + del queueList[uuid] + queueComplete = [] + if socket: + socket.emit("removedFinishedDownloads")