@@ -446,12 +446,15 @@ def login_session_file(
446446 self ,
447447 session_file : Path ,
448448 do_pkce : Optional [bool ] = False ,
449+ fn_print : Callable [[str ], None ] = print ,
449450 ) -> bool :
450451 """Logs in to the TIDAL api using an existing OAuth/PKCE session file. If no
451452 session json file exists, a new one will be created after successful login.
452453
453454 :param session_file: The session json file
454455 :param do_pkce: Perform PKCE login. Default: Use OAuth logon
456+ :param fn_print: A function which will be called to print the challenge text,
457+ defaults to `print()`.
455458 :return: Returns true if we think the login was successful.
456459 """
457460 self .load_session_from_file (session_file )
@@ -460,10 +463,10 @@ def login_session_file(
460463 if not self .check_login ():
461464 if do_pkce :
462465 log .info ("Creating new session (PKCE)..." )
463- self .login_pkce ()
466+ self .login_pkce (fn_print = fn_print )
464467 else :
465468 log .info ("Creating new session (OAuth)..." )
466- self .login_oauth_simple ()
469+ self .login_oauth_simple (fn_print = fn_print )
467470
468471 if self .check_login ():
469472 log .info ("TIDAL Login OK" )
@@ -576,17 +579,17 @@ def pkce_get_auth_token(self, url_redirect: str) -> dict[str, Union[str, int]]:
576579
577580 return token
578581
579- def login_oauth_simple (self , function : Callable [[str ], None ] = print ) -> None :
582+ def login_oauth_simple (self , fn_print : Callable [[str ], None ] = print ) -> None :
580583 """Login to TIDAL using a remote link. You can select what function you want to
581584 use to display the link.
582585
583- :param function : The function you want to display the link with
586+ :param fn_print : The function you want to display the link with
584587 :raises: TimeoutError: If the login takes too long
585588 """
586589
587590 login , future = self .login_oauth ()
588591 text = "Visit https://{0} to log in, the code will expire in {1} seconds"
589- function (text .format (login .verification_uri_complete , login .expires_in ))
592+ fn_print (text .format (login .verification_uri_complete , login .expires_in ))
590593 future .result ()
591594
592595 def login_oauth (self ) -> Tuple [LinkLogin , concurrent .futures .Future [Any ]]:
0 commit comments