Added Spotify credentials to settings tab

Reworked how spotify features work so now it doesn't require restart on 
config change
This commit is contained in:
RemixDev 2020-04-16 10:37:02 +02:00
parent 0d79904de8
commit 84c00d9d05
2 changed files with 23 additions and 10 deletions

24
app.py
View file

@ -1,16 +1,20 @@
import deemix.utils.localpaths as localpaths import deemix.utils.localpaths as localpaths
from deemix.app.queuemanager import addToQueue, removeFromQueue, getQueue, cancelAllDownloads, removeFinishedDownloads from deemix.app.queuemanager import addToQueue, removeFromQueue, getQueue, cancelAllDownloads, removeFinishedDownloads
from deemix.app.settings import initSettings, getSettings, saveSettings from deemix.app.settings import initSettings, getSettings, saveSettings
from deemix.app.spotify import SpotifyHelper
from os import system as execute from os import system as execute
settings = {} settings = {}
spotifyHelper = None
def getUser(dz): def getUser(dz):
return dz.user return dz.user
def initialize(): def initialize():
global settings global settings
global spotifyHelper
settings = initSettings() settings = initSettings()
spotifyHelper = SpotifyHelper()
def shutdown(interface=None): def shutdown(interface=None):
getQueue() getQueue()
@ -18,14 +22,16 @@ def shutdown(interface=None):
if interface: if interface:
interface.send("toast", {'msg': "Server is closed."}) interface.send("toast", {'msg': "Server is closed."})
# Search functions
def mainSearch(dz, term): def mainSearch(dz, term):
return dz.search_main_gw(term) return dz.search_main_gw(term)
def search(dz, 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)
# Queue functions
def addToQueue_link(dz, url, bitrate=None, interface=None): def addToQueue_link(dz, url, bitrate=None, interface=None):
return addToQueue(dz, url, settings, bitrate, interface) return addToQueue(dz, spotifyHelper, url, settings, bitrate, interface)
def removeFromQueue_link(uuid, interface=None): def removeFromQueue_link(uuid, interface=None):
removeFromQueue(uuid, interface) removeFromQueue(uuid, interface)
@ -36,16 +42,20 @@ def cancelAllDownloads_link(interface=None):
def removeFinishedDownloads_link(interface=None): def removeFinishedDownloads_link(interface=None):
removeFinishedDownloads(interface) removeFinishedDownloads(interface)
def getSettings_link():
return getSettings()
def getSettings_link():
return getSettings()
def getQueue_link(): def getQueue_link():
return getQueue() return getQueue()
# Settings functions
def getSettings_link():
return getSettings()
def saveSettings_link(newSettings): def saveSettings_link(newSettings):
global settings global settings
settings = newSettings settings = newSettings
return saveSettings(newSettings) return saveSettings(newSettings)
def getSpotifyCredentials():
return spotifyHelper.getCredentials()
def setSpotifyCredentials(newCredentials):
return spotifyHelper.setCredentials(newCredentials)

View file

@ -55,7 +55,9 @@ def closing():
@socketio.on('connect') @socketio.on('connect')
def on_connect(): def on_connect():
session['dz'] = Deezer() session['dz'] = Deezer()
emit('init_settings', app.getSettings_link()) settings = app.getSettings_link()
spotifyCredentials = app.getSpotifyCredentials()
emit('init_settings', (settings, spotifyCredentials))
queue, queueComplete, queueList, currentItem = app.getQueue_link() queue, queueComplete, queueList, currentItem = app.getQueue_link()
emit('init_downloadQueue', {'queue': queue, 'queueComplete': queueComplete, 'queueList': queueList, 'currentItem': currentItem}) emit('init_downloadQueue', {'queue': queue, 'queueComplete': queueComplete, 'queueList': queueList, 'currentItem': currentItem})
@ -113,9 +115,10 @@ def cancelAllDownloads():
app.cancelAllDownloads_link(interface=socket_interface) app.cancelAllDownloads_link(interface=socket_interface)
@socketio.on('saveSettings') @socketio.on('saveSettings')
def saveSettings(settings): def saveSettings(settings, spotifyCredentials):
app.saveSettings_link(settings) app.saveSettings_link(settings)
socket_interface.send('updateSettings', settings) app.setSpotifyCredentials(spotifyCredentials)
socketio.emit('updateSettings', (settings, spotifyCredentials))
def run_server(port): def run_server(port):
print("Starting server at http://127.0.0.1:"+str(port)) print("Starting server at http://127.0.0.1:"+str(port))