♻️ Renaming done to avoid confusion.

🛠️ Fixed config persisting error after read, if config file did not exist before (fixes #20).
✨ Implemented PKCE authorization to enable HiRes FLAC downloads. Fixes #9.
This commit is contained in:
Robert Honz
2024-01-23 09:51:59 +01:00
parent bd91967d1b
commit a347359931
2 changed files with 20 additions and 16 deletions
+10 -6
View File
@@ -8,7 +8,7 @@ import tidalapi
from requests import HTTPError
from tidal_dl_ng.helper.decorator import SingletonMeta
from tidal_dl_ng.helper.path import path_base, path_file_settings, path_file_token
from tidal_dl_ng.helper.path import path_config_base, path_file_settings, path_file_token
from tidal_dl_ng.model.cfg import Settings as ModelSettings
from tidal_dl_ng.model.cfg import Token as ModelToken
@@ -17,7 +17,7 @@ class BaseConfig:
data: ModelSettings | ModelToken = None
file_path: str = None
cls_model: object = None
path_base: str = path_base()
path_base: str = path_config_base()
def save(self, config_to_compare: str = None) -> None:
data_json = self.data.to_json()
@@ -36,7 +36,8 @@ class BaseConfig:
setattr(self.data, key, value)
def read(self, path: str) -> bool:
result = False
result: bool = False
settings_json: str = ""
try:
with open(path, encoding="utf-8") as f:
@@ -122,7 +123,7 @@ class Tidal(BaseConfig, metaclass=SingletonMeta):
def login_oauth_start(self, function=print) -> None:
self.session.login_oauth_simple(function)
def login_oauth_finish(self) -> bool:
def login_finish(self) -> bool:
result = self.session.check_login()
if result:
@@ -148,9 +149,9 @@ class Tidal(BaseConfig, metaclass=SingletonMeta):
elif not is_token:
fn_print("You either do not have a token or your token is invalid.")
fn_print("No worries, we will handle this...")
self.login_oauth_start(fn_print)
self.login_pkce(fn_print)
is_login = self.login_oauth_finish()
is_login = self.login_finish()
if is_login:
fn_print("The login was successful. I have stored your credentials (token).")
@@ -160,3 +161,6 @@ class Tidal(BaseConfig, metaclass=SingletonMeta):
fn_print("Something went wrong. Did you login using your browser correctly? May try again...")
return result
def login_pkce(self, fn_print: Callable) -> None:
self.session.login_pkce(fn_print)