Made deezer login session dependent and added login check

This commit is contained in:
RemixDev 2020-04-12 21:22:06 +02:00
parent 9e4ed4f045
commit f2b7e72021
2 changed files with 11 additions and 10 deletions

View File

@ -1,4 +1,3 @@
from deemix.api.deezer import Deezer
import deemix.utils.localpaths as localpaths import deemix.utils.localpaths as localpaths
from deemix.app.queuemanager import addToQueue, removeFromQueue, getQueue, cancelAllDownloads from deemix.app.queuemanager import addToQueue, removeFromQueue, getQueue, cancelAllDownloads
from deemix.app.settings import initSettings from deemix.app.settings import initSettings
@ -6,16 +5,15 @@ from os import system as execute
import os.path as path import os.path as path
from os import mkdir, rmdir from os import mkdir, rmdir
dz = Deezer()
settings = {} settings = {}
def login(arl): def login(dz, arl):
if not dz.logged_in: if not dz.logged_in:
return dz.login_via_arl(arl) return dz.login_via_arl(arl)
else: else:
return 2 return 2
def getUser(): def getUser(dz):
return dz.user return dz.user
def initialize(): def initialize():
@ -29,14 +27,14 @@ def shutdown(socket=None):
if socket: if socket:
socket.emit("toast", {'msg': "Server is closed."}) socket.emit("toast", {'msg': "Server is closed."})
def mainSearch(term): def mainSearch(dz, term):
return dz.search_main_gw(term) return dz.search_main_gw(term)
def search(term, type, start, nb): def search(dz, term, type, start, nb):
return dz.search_gw(term, type, start, nb) return dz.search_gw(term, type, start, nb)
def addToQueue_link(url, bitrate=None, socket=None): def addToQueue_link(dz, url, bitrate=None, socket=None):
addToQueue(dz, url, settings, bitrate, socket) return addToQueue(dz, url, settings, bitrate, socket)
def removeFromQueue_link(uuid, socket=None): def removeFromQueue_link(uuid, socket=None):
removeFromQueue(uuid, socket) removeFromQueue(uuid, socket)

View File

@ -153,6 +153,8 @@ def generateQueueItem(dz, url, settings, bitrate=None, albumAPI=None, socket=Non
def addToQueue(dz, url, settings, bitrate=None, socket=None): def addToQueue(dz, url, settings, bitrate=None, socket=None):
global currentItem, currentJob, queueList, queue global currentItem, currentJob, queueList, queue
if not dz.logged_in:
return "Not logged in"
queueItem = generateQueueItem(dz, url, settings, bitrate, socket=socket) queueItem = generateQueueItem(dz, url, settings, bitrate, socket=socket)
if type(queueItem) is list: if type(queueItem) is list:
for x in queueItem: for x in queueItem:
@ -169,18 +171,19 @@ def addToQueue(dz, url, settings, bitrate=None, socket=None):
if 'error' in queueItem: if 'error' in queueItem:
if socket: if socket:
socket.emit("toast", {'msg': queueItem['error']}) socket.emit("toast", {'msg': queueItem['error']})
return None return False
if queueItem['uuid'] in list(queueList.keys()): if queueItem['uuid'] in list(queueList.keys()):
print("Already in queue!") print("Already in queue!")
if socket: if socket:
socket.emit("toast", {'msg': f"{queueItem['title']} is already in queue!"}) socket.emit("toast", {'msg': f"{queueItem['title']} is already in queue!"})
return None return False
if socket: if socket:
socket.emit("addedToQueue", queueItem) socket.emit("addedToQueue", queueItem)
socket.emit("toast", {'msg': f"{queueItem['title']} added to queue"}) socket.emit("toast", {'msg': f"{queueItem['title']} added to queue"})
queue.append(queueItem['uuid']) queue.append(queueItem['uuid'])
queueList[queueItem['uuid']] = queueItem queueList[queueItem['uuid']] = queueItem
nextItem(dz, socket) nextItem(dz, socket)
return True
def nextItem(dz, socket=None): def nextItem(dz, socket=None):
global currentItem, currentJob, queueList, queue global currentItem, currentJob, queueList, queue