diff --git a/deemix/app/main.py b/deemix/app/main.py index d426a4f..8b45f12 100644 --- a/deemix/app/main.py +++ b/deemix/app/main.py @@ -1,6 +1,6 @@ from deemix.api.deezer import Deezer import deemix.utils.localpaths as localpaths -from deemix.app.queuemanager import addToQueue, removeFromQueue +from deemix.app.queuemanager import addToQueue, removeFromQueue, getQueue, cancelAllDownloads from deemix.app.settings import initSettings from os import system as execute import os.path as path @@ -36,6 +36,12 @@ def initialize(): login() return True +def shutdown(socket=None): + print(getQueue()) + cancelAllDownloads(socket) + if socket: + socket.emit("toast", {'msg': "Server is closed."}) + def mainSearch(term): return dz.search_main_gw(term) diff --git a/deemix/app/queuemanager.py b/deemix/app/queuemanager.py index 8c327bd..be7b910 100644 --- a/deemix/app/queuemanager.py +++ b/deemix/app/queuemanager.py @@ -198,11 +198,13 @@ def nextItem(dz, socket=None): def callbackQueueDone(result): global currentItem, currentJob, queueList, queue - result['socket'] del queueList[currentItem] currentItem = "" nextItem(result['dz'], result['socket']) +def getQueue(): + return (queue, queueList) + def removeFromQueue(uuid, socket=None): if uuid == currentItem: queueList[uuid]['cancel'] = True @@ -211,3 +213,13 @@ def removeFromQueue(uuid, socket=None): del queueList[uuid] if socket: socket.emit("removedFromQueue", uuid) + +def cancelAllDownloads(socket=None): + queue = [] + if currentItem != "": + queueList[currentItem]['cancel'] = True + for uuid in list(queueList.keys()): + if uuid != currentItem: + del queueList[uuid] + if socket: + socket.emit("removedAllDownloads")