summaryrefslogtreecommitdiff
path: root/tidal_dl_ng/gui.py
diff options
context:
space:
mode:
authorexislow <exislow@users.noreply.github.com>2024-02-01 07:42:08 +0100
committerGitHub <noreply@github.com>2024-02-01 07:42:08 +0100
commit2ec3314b0714bc938b068084723d31ff1a854f16 (patch)
treef84ec117c3ef57f7513ceb434c9e55835c0e441c /tidal_dl_ng/gui.py
parent7c0d2ab2eabfc8574f569752465035557baa2875 (diff)
parentce9afc1629c5fdb7ef74f2c5fcd9f9bdde527efc (diff)
downloadtidal-dl-ng-2ec3314b0714bc938b068084723d31ff1a854f16.tar.gz
Merge pull request #25 from exislow/pkce
Pkce
Diffstat (limited to 'tidal_dl_ng/gui.py')
-rw-r--r--tidal_dl_ng/gui.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py
index a12cd82..2a1b2d1 100644
--- a/tidal_dl_ng/gui.py
+++ b/tidal_dl_ng/gui.py
@@ -2,8 +2,10 @@ import math
import sys
from collections.abc import Callable
+from requests.exceptions import HTTPError
+
from tidal_dl_ng import __version__
-from tidal_dl_ng.dialog import DialogVersion
+from tidal_dl_ng.dialog import DialogLogin, DialogVersion
from tidal_dl_ng.helper.path import get_format_template
from tidal_dl_ng.helper.tidal import items_results_all, search_results_all, user_media_lists
@@ -85,12 +87,29 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
result = True
else:
self.tidal = Tidal(self.settings)
+ result = self.tidal.login_token()
+
+ if not result:
+ hint: str = "Watiting for user input."
+ while not result:
+ url_login = self.tidal.session.pkce_login_url()
+ d_login: DialogLogin = DialogLogin(url_login=url_login, hint=hint, parent=self)
+ url_redirect: str = d_login.url_redirect
- while True:
- result = self.tidal.login(logger_gui.info)
+ if d_login.return_code == 1:
+ try:
+ token: dict[str, str | int] = self.tidal.session.pkce_get_auth_token(url_redirect)
+ self.tidal.session.process_auth_token(token)
+ self.tidal.login_finalize()
- if result:
- break
+ result = True
+ logger_gui.info("Login not successful. Have fun!")
+ except (HTTPError, Exception):
+ hint = "Something was wrong with your redirect url. Please try again!"
+ logger_gui.warning("Login not successful. Try again...")
+ else:
+ # If user has pressed cancel.
+ sys.exit(1)
if result:
# Init `Download` object.