mirror of
https://gitlab.com/RemixDev/deemix-gui-pyweb.git
synced 2024-12-29 10:56:06 +00:00
Added in app login
Still need to fix the error "Release of profile requested but WebEnginePage still not deleted. Expect troubles !"
This commit is contained in:
parent
4a3882629b
commit
9a450c5672
|
@ -1,8 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QDialog, QVBoxLayout
|
||||||
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
|
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, QWebEngineProfile
|
||||||
from PyQt5.QtCore import QUrl, pyqtSignal
|
from PyQt5.QtCore import QUrl, pyqtSignal
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
from threading import Thread, Lock, Semaphore
|
from threading import Thread, Lock, Semaphore
|
||||||
import sys
|
import sys
|
||||||
import os.path as path
|
import os.path as path
|
||||||
|
@ -14,6 +16,48 @@ from deemix.utils.localpaths import getConfigFolder
|
||||||
|
|
||||||
server_lock = Lock()
|
server_lock = Lock()
|
||||||
|
|
||||||
|
class LoginWindow(QDialog):
|
||||||
|
|
||||||
|
class CustomPage(QWebEnginePage):
|
||||||
|
|
||||||
|
def acceptNavigationRequest(self, url, type, main):
|
||||||
|
if url.toString() == "https://www.deezer.com/":
|
||||||
|
url = QUrl('https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null')
|
||||||
|
self.setUrl(url)
|
||||||
|
return False
|
||||||
|
return super().acceptNavigationRequest(url, type, main)
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, parent):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.webview = QWebEngineView()
|
||||||
|
profile = QWebEngineProfile(self.webview)
|
||||||
|
profile.clearHttpCache()
|
||||||
|
profile.setPersistentCookiesPolicy(QWebEngineProfile.NoPersistentCookies)
|
||||||
|
profile.setHttpCacheType(QWebEngineProfile.NoCache)
|
||||||
|
self.page = self.CustomPage(profile, self.webview)
|
||||||
|
self.page.loadFinished.connect(self.checkURL)
|
||||||
|
self.webview.setPage(self.page)
|
||||||
|
self.webview.setUrl(QUrl("https://deezer.com/login"))
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
layout.addWidget(self.webview)
|
||||||
|
self.setLayout(layout)
|
||||||
|
self.arl = None
|
||||||
|
self.exec_()
|
||||||
|
|
||||||
|
def checkURL(self, ok):
|
||||||
|
url = self.webview.url().toString()
|
||||||
|
if 'user.getArl' in url:
|
||||||
|
sleep(1)
|
||||||
|
self.webview.page().toPlainText(self.saveARL)
|
||||||
|
|
||||||
|
def saveARL(self, body):
|
||||||
|
if body.startswith("{"):
|
||||||
|
self.arl = json.loads(body)['results']
|
||||||
|
self.accept()
|
||||||
|
self.page = None
|
||||||
|
self.webview = None
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
selectDownloadFolder_trigger = pyqtSignal()
|
selectDownloadFolder_trigger = pyqtSignal()
|
||||||
appLogin_trigger = pyqtSignal()
|
appLogin_trigger = pyqtSignal()
|
||||||
|
@ -52,10 +96,10 @@ class MainWindow(QMainWindow):
|
||||||
self._selectDownloadFolder_semaphore.release()
|
self._selectDownloadFolder_semaphore.release()
|
||||||
|
|
||||||
def appLogin(self):
|
def appLogin(self):
|
||||||
loginWindow = QWebEngineView()
|
loginWindow = LoginWindow(self)
|
||||||
loginWindow.setUrl(QUrl("https://deezer.com/login"))
|
self.arl = loginWindow.arl
|
||||||
loginWindow.show()
|
|
||||||
self._appLogin_semaphore.release()
|
self._appLogin_semaphore.release()
|
||||||
|
loginWindow.deleteLater()
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
x = int(self.x())
|
x = int(self.x())
|
||||||
|
|
42
server.py
42
server.py
|
@ -301,54 +301,16 @@ def selectDownloadFolder():
|
||||||
@socketio.on('applogin')
|
@socketio.on('applogin')
|
||||||
def applogin():
|
def applogin():
|
||||||
if gui:
|
if gui:
|
||||||
|
if not session['dz'].logged_in:
|
||||||
gui.appLogin_trigger.emit()
|
gui.appLogin_trigger.emit()
|
||||||
gui._appLogin_semaphore.acquire()
|
gui._appLogin_semaphore.acquire()
|
||||||
if gui.arl:
|
if gui.arl:
|
||||||
emit('applogin_arl', gui.arl)
|
emit('applogin_arl', gui.arl)
|
||||||
gui.arl = None
|
gui.arl = None
|
||||||
else:
|
else:
|
||||||
print("No ARL")
|
emit('logged_in', {'status': 2, 'user': session['dz'].user})
|
||||||
else:
|
else:
|
||||||
print("Can't open login page, you're not running the gui")
|
print("Can't open login page, you're not running the gui")
|
||||||
#try:
|
|
||||||
# import webview
|
|
||||||
# global loginWindow
|
|
||||||
# if not loginWindow:
|
|
||||||
# @copy_current_request_context
|
|
||||||
# def get_ARL():
|
|
||||||
# global loginWindow
|
|
||||||
# window = webview.windows[loginWindow]
|
|
||||||
# loginWindow = False
|
|
||||||
# window.loaded -= get_ARL
|
|
||||||
# arl = json.loads(window.get_elements("body")[0]['innerText'])['results']
|
|
||||||
# window.destroy()
|
|
||||||
# emit('applogin_arl', arl)
|
|
||||||
# @copy_current_request_context
|
|
||||||
# def check_URL():
|
|
||||||
# global loginWindow
|
|
||||||
# window = webview.windows[loginWindow]
|
|
||||||
# try:
|
|
||||||
# url = window.get_current_url()
|
|
||||||
# except:
|
|
||||||
# url = "https://www.deezer.com/us/login"
|
|
||||||
# if not "/login" in url:
|
|
||||||
# window.loaded -= check_URL
|
|
||||||
# window.loaded += get_ARL
|
|
||||||
# window.load_url('https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null')
|
|
||||||
# @copy_current_request_context
|
|
||||||
# def on_close():
|
|
||||||
# global loginWindow
|
|
||||||
# if loginWindow:
|
|
||||||
# loginWindow = False
|
|
||||||
# if not session['dz'].logged_in:
|
|
||||||
# window = webview.create_window('Login into your deezer account', "https://deezer.com/login")
|
|
||||||
# loginWindow = len(webview.windows)-1
|
|
||||||
# window.loaded += check_URL
|
|
||||||
# window.closed += on_close
|
|
||||||
# else:
|
|
||||||
# emit('logged_in', {'status': 2, 'user': session['dz'].user})
|
|
||||||
#except:
|
|
||||||
# print("Can't open folder selection, you're not running pywebview")
|
|
||||||
|
|
||||||
def run_server(port, host="127.0.0.1", portable=None, mainWindow=None):
|
def run_server(port, host="127.0.0.1", portable=None, mainWindow=None):
|
||||||
global app, gui
|
global app, gui
|
||||||
|
|
Loading…
Reference in a new issue