mirror of
https://gitlab.com/RemixDev/deemix-gui-pyweb.git
synced 2024-12-28 18:36:07 +00:00
Made app work with deemix lib 1.5.0
This commit is contained in:
parent
048f21b74b
commit
bc3d692417
22
app.py
22
app.py
|
@ -3,14 +3,14 @@ import eventlet
|
||||||
requests = eventlet.import_patched('requests')
|
requests = eventlet.import_patched('requests')
|
||||||
|
|
||||||
from deemix.api.deezer import Deezer
|
from deemix.api.deezer import Deezer
|
||||||
from deemix.app.settings import Settings
|
from deemix.app.settings import Settings, DEFAULT_SETTINGS
|
||||||
from deemix.app.queuemanager import QueueManager
|
from deemix.app.queuemanager import QueueManager
|
||||||
from deemix.app.spotifyhelper import SpotifyHelper, emptyPlaylist as emptySpotifyPlaylist
|
from deemix.app.spotifyhelper import SpotifyHelper, emptyPlaylist as emptySpotifyPlaylist
|
||||||
|
|
||||||
from deemix.utils import getTypeFromLink, getIDFromLink
|
from deemix.utils import getTypeFromLink, getIDFromLink
|
||||||
from deemix.utils.localpaths import getConfigFolder
|
from deemix.utils.localpaths import getConfigFolder
|
||||||
|
|
||||||
import os.path as path
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -19,11 +19,11 @@ def resource_path(relative_path):
|
||||||
""" Get absolute path to resource, works for dev and for PyInstaller """
|
""" Get absolute path to resource, works for dev and for PyInstaller """
|
||||||
try:
|
try:
|
||||||
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
||||||
base_path = sys._MEIPASS
|
base_path = Path(sys._MEIPASS)
|
||||||
except Exception:
|
except Exception:
|
||||||
base_path = path.dirname(path.abspath(path.realpath(__file__)))
|
base_path = Path(__file__).resolve().parent
|
||||||
|
|
||||||
return path.join(base_path, relative_path)
|
return Path(base_path) / relative_path
|
||||||
|
|
||||||
class LoginStatus():
|
class LoginStatus():
|
||||||
"""Login status codes"""
|
"""Login status codes"""
|
||||||
|
@ -60,7 +60,7 @@ class deemix:
|
||||||
|
|
||||||
def checkForUpdates(self):
|
def checkForUpdates(self):
|
||||||
commitFile = resource_path('version.txt')
|
commitFile = resource_path('version.txt')
|
||||||
if path.isfile(commitFile):
|
if commitFile.is_file():
|
||||||
print("Checking for updates...")
|
print("Checking for updates...")
|
||||||
with open(commitFile, 'r') as f:
|
with open(commitFile, 'r') as f:
|
||||||
self.currentVersion = f.read().strip()
|
self.currentVersion = f.read().strip()
|
||||||
|
@ -107,15 +107,15 @@ class deemix:
|
||||||
def getConfigArl(self):
|
def getConfigArl(self):
|
||||||
tempDeezer = Deezer()
|
tempDeezer = Deezer()
|
||||||
arl = None
|
arl = None
|
||||||
if path.isfile(path.join(self.configFolder, '.arl')):
|
if (self.configFolder / '.arl').is_file():
|
||||||
with open(path.join(self.configFolder, '.arl'), 'r') as f:
|
with open(self.configFolder / '.arl', 'r') as f:
|
||||||
arl = f.readline().rstrip("\n")
|
arl = f.readline().rstrip("\n")
|
||||||
if not arl or not tempDeezer.login_via_arl(arl):
|
if not arl or not tempDeezer.login_via_arl(arl):
|
||||||
while True:
|
while True:
|
||||||
arl = input("Paste here your arl:")
|
arl = input("Paste here your arl:")
|
||||||
if tempDeezer.login_via_arl(arl):
|
if tempDeezer.login_via_arl(arl):
|
||||||
break
|
break
|
||||||
with open(path.join(self.configFolder, '.arl'), 'w') as f:
|
with open(self.configFolder / '.arl', 'w') as f:
|
||||||
f.write(arl)
|
f.write(arl)
|
||||||
return arl
|
return arl
|
||||||
|
|
||||||
|
@ -284,10 +284,10 @@ class deemix:
|
||||||
|
|
||||||
# Settings functions
|
# Settings functions
|
||||||
def getAllSettings(self):
|
def getAllSettings(self):
|
||||||
return (self.set.settings, self.sp.getCredentials(), self.set.defaultSettings)
|
return (self.set.settings, self.sp.getCredentials(), DEFAULT_SETTINGS)
|
||||||
|
|
||||||
def getDefaultSettings(self):
|
def getDefaultSettings(self):
|
||||||
return self.set.defaultSettings
|
return DEFAULT_SETTINGS
|
||||||
|
|
||||||
def getSettings(self):
|
def getSettings(self):
|
||||||
return self.set.settings
|
return self.set.settings
|
||||||
|
|
|
@ -9,7 +9,8 @@ import webbrowser
|
||||||
|
|
||||||
from threading import Thread, Semaphore
|
from threading import Thread, Semaphore
|
||||||
import sys
|
import sys
|
||||||
import os.path as path
|
from pathlib import Path
|
||||||
|
from os.path import sep as pathSep
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from server import run_server
|
from server import run_server
|
||||||
|
@ -109,7 +110,7 @@ class MainWindow(QMainWindow):
|
||||||
else:
|
else:
|
||||||
self.resize(w, h)
|
self.resize(w, h)
|
||||||
self.setWindowTitle(title)
|
self.setWindowTitle(title)
|
||||||
self.setWindowIcon(QIcon(path.join(appDir, 'icon.ico')))
|
self.setWindowIcon(QIcon(str(appDir / 'icon.ico')))
|
||||||
self.setMinimumSize(800, 600)
|
self.setMinimumSize(800, 600)
|
||||||
self.webview = QWebEngineView()
|
self.webview = QWebEngineView()
|
||||||
self.page = self.MainWebpage(self.webview)
|
self.page = self.MainWebpage(self.webview)
|
||||||
|
@ -145,7 +146,7 @@ class MainWindow(QMainWindow):
|
||||||
|
|
||||||
def selectDownloadFolder(self):
|
def selectDownloadFolder(self):
|
||||||
filename = QFileDialog.getExistingDirectory(self, "Select Download Folder", options=QFileDialog.ShowDirsOnly)
|
filename = QFileDialog.getExistingDirectory(self, "Select Download Folder", options=QFileDialog.ShowDirsOnly)
|
||||||
self.downloadFolder = filename.replace('/', path.sep)
|
self.downloadFolder = filename.replace('/', pathSep)
|
||||||
self._selectDownloadFolder_semaphore.release()
|
self._selectDownloadFolder_semaphore.release()
|
||||||
|
|
||||||
def appLogin(self):
|
def appLogin(self):
|
||||||
|
@ -167,7 +168,7 @@ class MainWindow(QMainWindow):
|
||||||
if self.isMaximized():
|
if self.isMaximized():
|
||||||
w = -1
|
w = -1
|
||||||
h = -1
|
h = -1
|
||||||
with open(path.join(configFolder, '.UIposition'), 'w') as f:
|
with open(configFolder / '.UIposition', 'w') as f:
|
||||||
f.write("|".join([str(x),str(y),str(w),str(h)]))
|
f.write("|".join([str(x),str(y),str(w),str(h)]))
|
||||||
event.accept()
|
event.accept()
|
||||||
|
|
||||||
|
@ -185,9 +186,9 @@ def url_ok(url, port):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_position():
|
def get_position():
|
||||||
if path.isfile(path.join(configFolder, '.UIposition')):
|
if (configFolder / '.UIposition').is_file():
|
||||||
try:
|
try:
|
||||||
with open(path.join(configFolder, '.UIposition'), 'r') as f:
|
with open(configFolder / '.UIposition', 'r') as f:
|
||||||
(x,y,w,h) = f.read().strip().split("|")
|
(x,y,w,h) = f.read().strip().split("|")
|
||||||
x = int(x)
|
x = int(x)
|
||||||
y = int(y)
|
y = int(y)
|
||||||
|
@ -216,9 +217,9 @@ if __name__ == '__main__':
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
portable = None
|
portable = None
|
||||||
appDir = path.dirname(path.realpath(__file__))
|
appDir = Path(__file__).parent
|
||||||
if '--portable' in sys.argv:
|
if '--portable' in sys.argv:
|
||||||
portable = path.join(appDir, 'config')
|
portable = appDir / 'config'
|
||||||
server = '--server' in sys.argv or '-s' in sys.argv
|
server = '--server' in sys.argv or '-s' in sys.argv
|
||||||
dev = '--dev' in sys.argv
|
dev = '--dev' in sys.argv
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
deemix>=1.4.3
|
deemix>=1.5.0
|
||||||
flask
|
flask
|
||||||
flask-socketio
|
flask-socketio
|
||||||
eventlet
|
eventlet
|
||||||
|
|
17
server.py
17
server.py
|
@ -2,9 +2,14 @@
|
||||||
import logging
|
import logging
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
from os import path
|
from pathlib import Path
|
||||||
|
from os.path import sep as pathSep
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
# Import needed to set all sequential requests import eventlet compatible
|
||||||
|
import eventlet
|
||||||
|
requests = eventlet.import_patched('requests')
|
||||||
|
|
||||||
from eventlet import tpool
|
from eventlet import tpool
|
||||||
from eventlet.green import subprocess
|
from eventlet.green import subprocess
|
||||||
|
|
||||||
|
@ -56,13 +61,13 @@ class CustomFlask(Flask):
|
||||||
|
|
||||||
# Retrocompatibility with old versions of the app
|
# Retrocompatibility with old versions of the app
|
||||||
# Check for public folder and fallback to webui
|
# Check for public folder and fallback to webui
|
||||||
GUI_DIR = resource_path(path.join('webui', 'public'))
|
GUI_DIR = resource_path(f'webui{pathSep}public')
|
||||||
if not path.exists(GUI_DIR):
|
if not GUI_DIR.exists():
|
||||||
GUI_DIR = resource_path('webui')
|
GUI_DIR = resource_path('webui')
|
||||||
if not path.isfile(path.join(GUI_DIR, 'index.html')):
|
if not (GUI_DIR / 'index.html').is_file():
|
||||||
sys.exit("WebUI not found, please download and add a WebUI")
|
sys.exit("WebUI not found, please download and add a WebUI")
|
||||||
|
|
||||||
server = CustomFlask(__name__, static_folder=GUI_DIR, template_folder=GUI_DIR, static_url_path="")
|
server = CustomFlask(__name__, static_folder=str(GUI_DIR), template_folder=str(GUI_DIR), static_url_path="")
|
||||||
server.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1 # disable caching
|
server.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1 # disable caching
|
||||||
socketio = SocketIO(server)
|
socketio = SocketIO(server)
|
||||||
server.wsgi_app = ProxyFix(server.wsgi_app, x_for=1, x_proto=1)
|
server.wsgi_app = ProxyFix(server.wsgi_app, x_for=1, x_proto=1)
|
||||||
|
@ -354,7 +359,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
portable = None
|
portable = None
|
||||||
if '--portable' in sys.argv:
|
if '--portable' in sys.argv:
|
||||||
portable = path.join(path.dirname(path.realpath(__file__)), 'config')
|
portable = Path(__file__).parent / 'config'
|
||||||
if '--host' in sys.argv:
|
if '--host' in sys.argv:
|
||||||
host = str(sys.argv[sys.argv.index("--host")+1])
|
host = str(sys.argv[sys.argv.index("--host")+1])
|
||||||
serverwide_arl = "--serverwide-arl" in sys.argv
|
serverwide_arl = "--serverwide-arl" in sys.argv
|
||||||
|
|
Loading…
Reference in a new issue