@@ -96,7 +96,7 @@ def __init__(
9696 self .authenticate (session_builder .login_credentials )
9797
9898 @staticmethod
99- def from_file (cred_file : Path | str , language : str = "en" ) -> Session :
99+ def from_file (auth : OAuth , cred_file : Path | str , language : str = "en" ) -> Session :
100100 """
101101 Creates session using saved credentials file
102102 Args:
@@ -113,11 +113,13 @@ def from_file(cred_file: Path | str, language: str = "en") -> Session:
113113 .build ()
114114 )
115115 session = LibrespotSession .Builder (conf ).stored_file (str (cred_file ))
116- return Session (session , OAuth () , language ) # TODO
116+ return Session (session , auth , language ) # TODO
117117
118118 @staticmethod
119119 def from_oauth (
120- save_file : Path | str | None = None , language : str = "en"
120+ auth : OAuth ,
121+ save_file : Path | str | None = None ,
122+ language : str = "en" ,
121123 ) -> Session :
122124 """
123125 Creates a session using OAuth2
@@ -136,15 +138,11 @@ def from_oauth(
136138 else :
137139 builder .set_store_credentials (False )
138140
139- # TODO: this should be done in App()
140- username = input ("Username: " )
141- auth = OAuth ()
142- print (f"Click on the following link to login:\n { auth .get_authorization_url ()} " )
143141 token = auth .await_token ()
144142
145143 session = LibrespotSession .Builder (builder .build ())
146144 session .login_credentials = Authentication .LoginCredentials (
147- username = username ,
145+ username = auth . username ,
148146 typ = Authentication .AuthenticationType .values ()[3 ],
149147 auth_data = token .access_token .encode (),
150148 )
@@ -221,11 +219,7 @@ def authenticate(self, credential: Authentication.LoginCredentials) -> None:
221219 self .__event_service = EventService (self )
222220 self .__auth_lock_bool = False
223221 self .__auth_lock .notify_all ()
224- self .dealer ().connect ()
225222 self .mercury ().interested_in ("sp" + "otify:user:attributes:update" , self )
226- self .dealer ().add_message_listener (
227- self , ["hm://connect-state/v1/connect/logout" ]
228- )
229223
230224
231225class ApiClient (LibrespotApiClient ):
@@ -303,8 +297,10 @@ class OAuth:
303297 __code_verifier : str
304298 __server_thread : Thread
305299 __token : TokenProvider .StoredToken
300+ username : str
306301
307- def __init__ (self ):
302+ def __init__ (self , username : str ):
303+ self .username = username
308304 self .__server_thread = Thread (target = self .__run_server )
309305 self .__server_thread .start ()
310306
0 commit comments