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:
RemixDev 2020-08-22 00:26:32 +02:00
parent 4a3882629b
commit 9a450c5672
2 changed files with 57 additions and 51 deletions

View file

@ -1,8 +1,10 @@
#!/usr/bin/env python3
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QDialog, QVBoxLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, QWebEngineProfile
from PyQt5.QtCore import QUrl, pyqtSignal
import json
from threading import Thread, Lock, Semaphore
import sys
import os.path as path
@ -14,6 +16,48 @@ from deemix.utils.localpaths import getConfigFolder
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):
selectDownloadFolder_trigger = pyqtSignal()
appLogin_trigger = pyqtSignal()
@ -27,7 +71,7 @@ class MainWindow(QMainWindow):
self.webview.page().loadFinished.connect(self.finishLoading)
self.setCentralWidget(self.webview)
self.url = url
self.downloadFolder = None
self.selectDownloadFolder_trigger.connect(self.selectDownloadFolder)
self._selectDownloadFolder_semaphore = Semaphore(0)
@ -52,10 +96,10 @@ class MainWindow(QMainWindow):
self._selectDownloadFolder_semaphore.release()
def appLogin(self):
loginWindow = QWebEngineView()
loginWindow.setUrl(QUrl("https://deezer.com/login"))
loginWindow.show()
loginWindow = LoginWindow(self)
self.arl = loginWindow.arl
self._appLogin_semaphore.release()
loginWindow.deleteLater()
def closeEvent(self, event):
x = int(self.x())

View file

@ -301,54 +301,16 @@ def selectDownloadFolder():
@socketio.on('applogin')
def applogin():
if gui:
gui.appLogin_trigger.emit()
gui._appLogin_semaphore.acquire()
if gui.arl:
emit('applogin_arl', gui.arl)
gui.arl = None
if not session['dz'].logged_in:
gui.appLogin_trigger.emit()
gui._appLogin_semaphore.acquire()
if gui.arl:
emit('applogin_arl', gui.arl)
gui.arl = None
else:
print("No ARL")
emit('logged_in', {'status': 2, 'user': session['dz'].user})
else:
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):
global app, gui