mirror of
https://gitlab.com/RemixDev/deemix-gui-pyweb.git
synced 2025-01-15 11:05:16 +00:00
optimized import and other small changes
This commit is contained in:
parent
122bc3f818
commit
a4693bb537
16
app.py
16
app.py
|
@ -1,61 +1,73 @@
|
|||
import deemix.utils.localpaths as localpaths
|
||||
from deemix.app.queuemanager import addToQueue, removeFromQueue, getQueue, cancelAllDownloads, removeFinishedDownloads
|
||||
from deemix.app.settings import initSettings, getSettings, saveSettings
|
||||
from deemix.app.spotify import SpotifyHelper
|
||||
from os import system as execute
|
||||
|
||||
settings = {}
|
||||
spotifyHelper = None
|
||||
|
||||
|
||||
def getUser(dz):
|
||||
return dz.user
|
||||
|
||||
|
||||
def initialize():
|
||||
global settings
|
||||
global spotifyHelper
|
||||
settings = initSettings()
|
||||
spotifyHelper = SpotifyHelper()
|
||||
|
||||
|
||||
def shutdown(interface=None):
|
||||
getQueue()
|
||||
cancelAllDownloads(interface)
|
||||
if interface:
|
||||
interface.send("toast", {'msg': "Server is closed."})
|
||||
|
||||
|
||||
# Search functions
|
||||
def mainSearch(dz, term):
|
||||
return dz.search_main_gw(term)
|
||||
|
||||
|
||||
def search(dz, term, type, start, nb):
|
||||
return dz.search(term, type, nb, start)
|
||||
|
||||
|
||||
# Queue functions
|
||||
def addToQueue_link(dz, url, bitrate=None, interface=None):
|
||||
return addToQueue(dz, spotifyHelper, url, settings, bitrate, interface)
|
||||
|
||||
|
||||
def removeFromQueue_link(uuid, interface=None):
|
||||
removeFromQueue(uuid, interface)
|
||||
|
||||
|
||||
def cancelAllDownloads_link(interface=None):
|
||||
cancelAllDownloads(interface)
|
||||
|
||||
|
||||
def removeFinishedDownloads_link(interface=None):
|
||||
removeFinishedDownloads(interface)
|
||||
|
||||
|
||||
def getQueue_link():
|
||||
return getQueue()
|
||||
|
||||
|
||||
# Settings functions
|
||||
def getSettings_link():
|
||||
return getSettings()
|
||||
|
||||
|
||||
def saveSettings_link(newSettings):
|
||||
global settings
|
||||
settings = newSettings
|
||||
return saveSettings(newSettings)
|
||||
|
||||
|
||||
def getSpotifyCredentials():
|
||||
return spotifyHelper.getCredentials()
|
||||
|
||||
|
||||
def setSpotifyCredentials(newCredentials):
|
||||
return spotifyHelper.setCredentials(newCredentials)
|
||||
|
|
30
server.py
30
server.py
|
@ -1,14 +1,14 @@
|
|||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from flask import Flask, render_template, request, session
|
||||
from flask_socketio import SocketIO, emit
|
||||
import logging
|
||||
|
||||
import app
|
||||
from deemix.api.deezer import Deezer
|
||||
from deemix.app.MessageInterface import MessageInterface
|
||||
import app
|
||||
import time
|
||||
import sys
|
||||
|
||||
|
||||
class CustomFlask(Flask):
|
||||
jinja_options = Flask.jinja_options.copy()
|
||||
|
@ -29,6 +29,7 @@ server = CustomFlask(__name__, static_folder=gui_dir, template_folder=gui_dir)
|
|||
server.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1 # disable caching
|
||||
socketio = SocketIO(server)
|
||||
|
||||
|
||||
class SocketInterface(MessageInterface):
|
||||
def send(self, message, value=None):
|
||||
if value:
|
||||
|
@ -36,6 +37,7 @@ class SocketInterface(MessageInterface):
|
|||
else:
|
||||
socketio.emit(message)
|
||||
|
||||
|
||||
socket_interface = SocketInterface()
|
||||
|
||||
serverLog = logging.getLogger('werkzeug')
|
||||
|
@ -44,10 +46,12 @@ server.logger.disabled = True
|
|||
|
||||
app.initialize()
|
||||
|
||||
|
||||
@server.route('/')
|
||||
def landing():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@server.route('/shutdown')
|
||||
def closing():
|
||||
app.shutdown(interface=socket_interface)
|
||||
|
@ -55,6 +59,7 @@ def closing():
|
|||
func()
|
||||
return 'server closed'
|
||||
|
||||
|
||||
@socketio.on('connect')
|
||||
def on_connect():
|
||||
session['dz'] = Deezer()
|
||||
|
@ -62,7 +67,9 @@ def on_connect():
|
|||
spotifyCredentials = app.getSpotifyCredentials()
|
||||
emit('init_settings', (settings, spotifyCredentials))
|
||||
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})
|
||||
|
||||
|
||||
@socketio.on('login')
|
||||
def login(arl, force=False):
|
||||
|
@ -79,6 +86,7 @@ def login(arl, force=False):
|
|||
result = 2
|
||||
emit('logged_in', {'status': result, 'arl': arl, 'user': app.getUser(session['dz'])})
|
||||
|
||||
|
||||
@socketio.on('logout')
|
||||
def logout():
|
||||
status = 0
|
||||
|
@ -89,40 +97,48 @@ def logout():
|
|||
status = 1
|
||||
emit('logged_out', status)
|
||||
|
||||
|
||||
@socketio.on('mainSearch')
|
||||
def mainSearch(data):
|
||||
emit('mainSearch', app.mainSearch(session['dz'], data['term']))
|
||||
|
||||
|
||||
@socketio.on('search')
|
||||
def search(data):
|
||||
result = app.search(session['dz'], data['term'], data['type'], data['start'], data['nb'])
|
||||
result['type'] = data['type']
|
||||
emit('search', result)
|
||||
|
||||
|
||||
@socketio.on('addToQueue')
|
||||
def addToQueue(data):
|
||||
result = app.addToQueue_link(session['dz'], data['url'], data['bitrate'], interface=socket_interface)
|
||||
if result == "Not logged in":
|
||||
emit('toast', {'msg': "You need to log in to download tracks!", 'icon': 'report'})
|
||||
|
||||
|
||||
@socketio.on('removeFromQueue')
|
||||
def removeFromQueue(uuid):
|
||||
app.removeFromQueue_link(uuid, interface=socket_interface)
|
||||
|
||||
|
||||
@socketio.on('removeFinishedDownloads')
|
||||
def removeFinishedDownloads():
|
||||
app.removeFinishedDownloads_link(interface=socket_interface)
|
||||
|
||||
|
||||
@socketio.on('cancelAllDownloads')
|
||||
def cancelAllDownloads():
|
||||
app.cancelAllDownloads_link(interface=socket_interface)
|
||||
|
||||
|
||||
@socketio.on('saveSettings')
|
||||
def saveSettings(settings, spotifyCredentials):
|
||||
app.saveSettings_link(settings)
|
||||
app.setSpotifyCredentials(spotifyCredentials)
|
||||
socketio.emit('updateSettings', (settings, spotifyCredentials))
|
||||
|
||||
|
||||
@socketio.on('getTracklist')
|
||||
def getTracklist(data):
|
||||
if data['type'] == 'artist':
|
||||
|
@ -153,10 +169,12 @@ def getTracklist(data):
|
|||
releaseAPI['tracks'] = tracks
|
||||
emit('show_' + data['type'], releaseAPI)
|
||||
|
||||
|
||||
def run_server(port):
|
||||
print("Starting server at http://127.0.0.1:" + str(port))
|
||||
socketio.run(server, host='0.0.0.0', port=port)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) >= 2:
|
||||
port = int(sys.argv[1])
|
||||
|
|
Loading…
Reference in a new issue