From a3473599316779b04a30de4a01bf893a68428219 Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Tue, 23 Jan 2024 09:51:59 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Renaming=20done=20to=20avo?= =?UTF-8?q?id=20confusion.=20=F0=9F=9B=A0=EF=B8=8F=20Fixed=20config=20pers?= =?UTF-8?q?isting=20error=20after=20read,=20if=20config=20file=20did=20not?= =?UTF-8?q?=20exist=20before=20(fixes=20#20).=20=E2=9C=A8=20Implemented=20?= =?UTF-8?q?PKCE=20authorization=20to=20enable=20HiRes=20FLAC=20downloads.?= =?UTF-8?q?=20Fixes=20#9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidal_dl_ng/config.py | 16 ++++++++++------ tidal_dl_ng/helper/path.py | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/tidal_dl_ng/config.py b/tidal_dl_ng/config.py index 95d30d9..7c91e26 100644 --- a/tidal_dl_ng/config.py +++ b/tidal_dl_ng/config.py @@ -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) diff --git a/tidal_dl_ng/helper/path.py b/tidal_dl_ng/helper/path.py index a2ce98c..373f78c 100644 --- a/tidal_dl_ng/helper/path.py +++ b/tidal_dl_ng/helper/path.py @@ -23,7 +23,7 @@ def path_home() -> str: return os.path.abspath("./") -def path_base() -> str: +def path_config_base() -> str: path_config: str = ".config" path_base: str = os.path.join(path_home(), path_config, __name_display__) @@ -34,30 +34,30 @@ def path_file_log() -> str: # TODO: Remove this soon. Only for migration to new dir. old = os.path.join(path_home(), ".tidal-dl-ng.log") if os.path.isfile(old): - os.makedirs(path_base(), exist_ok=True) - os.rename(old, os.path.join(path_base(), "app.log")) + os.makedirs(path_config_base(), exist_ok=True) + os.rename(old, os.path.join(path_config_base(), "app.log")) - return os.path.join(path_base(), "app.log") + return os.path.join(path_config_base(), "app.log") def path_file_token() -> str: # TODO: Remove this soon. Only for migration to new dir. old = os.path.join(path_home(), ".tidal-dl-ng_token.json") if os.path.isfile(old): - os.makedirs(path_base(), exist_ok=True) - os.rename(old, os.path.join(path_base(), "token.json")) + os.makedirs(path_config_base(), exist_ok=True) + os.rename(old, os.path.join(path_config_base(), "token.json")) - return os.path.join(path_base(), "token.json") + return os.path.join(path_config_base(), "token.json") def path_file_settings() -> str: # TODO: Remove this soon. Only for migration to new dir. old = os.path.join(path_home(), ".tidal-dl-ng_settings.json") if os.path.isfile(old): - os.makedirs(path_base(), exist_ok=True) - os.rename(old, os.path.join(path_base(), "settings.json")) + os.makedirs(path_config_base(), exist_ok=True) + os.rename(old, os.path.join(path_config_base(), "settings.json")) - return os.path.join(path_base(), "settings.json") + return os.path.join(path_config_base(), "settings.json") def format_path_media(fmt_template: str, media: Track | Album | Playlist | UserPlaylist | Video | Mix) -> str: