Made app work with deemix lib 1.5.0

This commit is contained in:
RemixDev 2020-09-27 23:45:01 +02:00
parent 048f21b74b
commit bc3d692417
4 changed files with 32 additions and 26 deletions

22
app.py
View file

@ -3,14 +3,14 @@ import eventlet
requests = eventlet.import_patched('requests')
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.spotifyhelper import SpotifyHelper, emptyPlaylist as emptySpotifyPlaylist
from deemix.utils import getTypeFromLink, getIDFromLink
from deemix.utils.localpaths import getConfigFolder
import os.path as path
from pathlib import Path
import json
from datetime import datetime
@ -19,11 +19,11 @@ def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
base_path = Path(sys._MEIPASS)
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():
"""Login status codes"""
@ -60,7 +60,7 @@ class deemix:
def checkForUpdates(self):
commitFile = resource_path('version.txt')
if path.isfile(commitFile):
if commitFile.is_file():
print("Checking for updates...")
with open(commitFile, 'r') as f:
self.currentVersion = f.read().strip()
@ -107,15 +107,15 @@ class deemix:
def getConfigArl(self):
tempDeezer = Deezer()
arl = None
if path.isfile(path.join(self.configFolder, '.arl')):
with open(path.join(self.configFolder, '.arl'), 'r') as f:
if (self.configFolder / '.arl').is_file():
with open(self.configFolder / '.arl', 'r') as f:
arl = f.readline().rstrip("\n")
if not arl or not tempDeezer.login_via_arl(arl):
while True:
arl = input("Paste here your arl:")
if tempDeezer.login_via_arl(arl):
break
with open(path.join(self.configFolder, '.arl'), 'w') as f:
with open(self.configFolder / '.arl', 'w') as f:
f.write(arl)
return arl
@ -284,10 +284,10 @@ class deemix:
# Settings functions
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):
return self.set.defaultSettings
return DEFAULT_SETTINGS
def getSettings(self):
return self.set.settings

View file

@ -9,7 +9,8 @@ import webbrowser
from threading import Thread, Semaphore
import sys
import os.path as path
from pathlib import Path
from os.path import sep as pathSep
from os import makedirs
from time import sleep
from server import run_server
@ -109,7 +110,7 @@ class MainWindow(QMainWindow):
else:
self.resize(w, h)
self.setWindowTitle(title)
self.setWindowIcon(QIcon(path.join(appDir, 'icon.ico')))
self.setWindowIcon(QIcon(str(appDir / 'icon.ico')))
self.setMinimumSize(800, 600)
self.webview = QWebEngineView()
self.page = self.MainWebpage(self.webview)
@ -145,7 +146,7 @@ class MainWindow(QMainWindow):
def selectDownloadFolder(self):
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()
def appLogin(self):
@ -167,7 +168,7 @@ class MainWindow(QMainWindow):
if self.isMaximized():
w = -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)]))
event.accept()
@ -185,9 +186,9 @@ def url_ok(url, port):
return False
def get_position():
if path.isfile(path.join(configFolder, '.UIposition')):
if (configFolder / '.UIposition').is_file():
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 = int(x)
y = int(y)
@ -216,9 +217,9 @@ if __name__ == '__main__':
except ValueError:
pass
portable = None
appDir = path.dirname(path.realpath(__file__))
appDir = Path(__file__).parent
if '--portable' in sys.argv:
portable = path.join(appDir, 'config')
portable = appDir / 'config'
server = '--server' in sys.argv or '-s' in sys.argv
dev = '--dev' in sys.argv

View file

@ -1,4 +1,4 @@
deemix>=1.4.3
deemix>=1.5.0
flask
flask-socketio
eventlet

View file

@ -2,9 +2,14 @@
import logging
import signal
import sys
from os import path
from pathlib import Path
from os.path import sep as pathSep
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.green import subprocess
@ -56,13 +61,13 @@ class CustomFlask(Flask):
# Retrocompatibility with old versions of the app
# Check for public folder and fallback to webui
GUI_DIR = resource_path(path.join('webui', 'public'))
if not path.exists(GUI_DIR):
GUI_DIR = resource_path(f'webui{pathSep}public')
if not GUI_DIR.exists():
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")
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
socketio = SocketIO(server)
server.wsgi_app = ProxyFix(server.wsgi_app, x_for=1, x_proto=1)
@ -354,7 +359,7 @@ if __name__ == '__main__':
portable = None
if '--portable' in sys.argv:
portable = path.join(path.dirname(path.realpath(__file__)), 'config')
portable = Path(__file__).parent / 'config'
if '--host' in sys.argv:
host = str(sys.argv[sys.argv.index("--host")+1])
serverwide_arl = "--serverwide-arl" in sys.argv