From 3f3bdcd3de3f064550036c966ed4b61b61e8106f Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Mon, 16 Sep 2024 09:39:25 +0200 Subject: [PATCH 1/4] Add optional fn_print to Session::login_session_file --- tidalapi/session.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tidalapi/session.py b/tidalapi/session.py index 9aa3df1..55983a7 100644 --- a/tidalapi/session.py +++ b/tidalapi/session.py @@ -446,12 +446,15 @@ def login_session_file( self, session_file: Path, do_pkce: Optional[bool] = False, + fn_print: Callable[[str], None] = print ) -> bool: """Logs in to the TIDAL api using an existing OAuth/PKCE session file. If no session json file exists, a new one will be created after successful login. :param session_file: The session json file :param do_pkce: Perform PKCE login. Default: Use OAuth logon + :param fn_print: A function which will be called to print the the challenge text, + defaults to `print()`. :return: Returns true if we think the login was successful. """ self.load_session_from_file(session_file) @@ -460,10 +463,10 @@ def login_session_file( if not self.check_login(): if do_pkce: log.info("Creating new session (PKCE)...") - self.login_pkce() + self.login_pkce(fn_print=fn_print) else: log.info("Creating new session (OAuth)...") - self.login_oauth_simple() + self.login_oauth_simple(function=fn_print) if self.check_login(): log.info("TIDAL Login OK") From b4cae2f931ebc6542864b82a032ecc3b24ad5298 Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Mon, 16 Sep 2024 09:42:47 +0200 Subject: [PATCH 2/4] Fixed typo --- tidalapi/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidalapi/session.py b/tidalapi/session.py index 55983a7..e7f6649 100644 --- a/tidalapi/session.py +++ b/tidalapi/session.py @@ -453,7 +453,7 @@ def login_session_file( :param session_file: The session json file :param do_pkce: Perform PKCE login. Default: Use OAuth logon - :param fn_print: A function which will be called to print the the challenge text, + :param fn_print: A function which will be called to print the challenge text, defaults to `print()`. :return: Returns true if we think the login was successful. """ From 38438bf1a4af391126e9fc36fd0eef7cafaf1da8 Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Mon, 30 Sep 2024 09:01:54 +0200 Subject: [PATCH 3/4] Rename print function to fn_print in login_session_file as well --- docs/login.rst | 2 +- tidalapi/session.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/login.rst b/docs/login.rst index ac43efe..6278cbf 100644 --- a/docs/login.rst +++ b/docs/login.rst @@ -46,7 +46,7 @@ This will print the link, and then wait for the login future to complete, but it .. testcode:: # The function is print by default, but you can use anything, here we do it to avoid the print being swallowed - session.login_oauth_simple(function=printer) + session.login_oauth_simple(fn_print=printer) print(session.check_login()) .. testoutput:: diff --git a/tidalapi/session.py b/tidalapi/session.py index e7f6649..dc6b7f9 100644 --- a/tidalapi/session.py +++ b/tidalapi/session.py @@ -466,7 +466,7 @@ def login_session_file( self.login_pkce(fn_print=fn_print) else: log.info("Creating new session (OAuth)...") - self.login_oauth_simple(function=fn_print) + self.login_oauth_simple(fn_print=fn_print) if self.check_login(): log.info("TIDAL Login OK") @@ -579,17 +579,17 @@ def pkce_get_auth_token(self, url_redirect: str) -> dict[str, Union[str, int]]: return token - def login_oauth_simple(self, function: Callable[[str], None] = print) -> None: + def login_oauth_simple(self, fn_print: Callable[[str], None] = print) -> None: """Login to TIDAL using a remote link. You can select what function you want to use to display the link. - :param function: The function you want to display the link with + :param fn_print: The function you want to display the link with :raises: TimeoutError: If the login takes too long """ login, future = self.login_oauth() text = "Visit https://{0} to log in, the code will expire in {1} seconds" - function(text.format(login.verification_uri_complete, login.expires_in)) + fn_print(text.format(login.verification_uri_complete, login.expires_in)) future.result() def login_oauth(self) -> Tuple[LinkLogin, concurrent.futures.Future[Any]]: From 7b4ee42904182457115688b5419e7bca4cdc0fe9 Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Mon, 30 Sep 2024 09:06:08 +0200 Subject: [PATCH 4/4] Fix linting issue - I never thought it could be the comma --- tidalapi/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidalapi/session.py b/tidalapi/session.py index dc6b7f9..3b323a1 100644 --- a/tidalapi/session.py +++ b/tidalapi/session.py @@ -446,7 +446,7 @@ def login_session_file( self, session_file: Path, do_pkce: Optional[bool] = False, - fn_print: Callable[[str], None] = print + fn_print: Callable[[str], None] = print, ) -> bool: """Logs in to the TIDAL api using an existing OAuth/PKCE session file. If no session json file exists, a new one will be created after successful login.