@@ -70,8 +70,8 @@ class Session(LibrespotSession):
7070 def __init__ (
7171 self ,
7272 session_builder : LibrespotSession .Builder ,
73- oauth : OAuth ,
7473 language : str = "en" ,
74+ oauth : OAuth | None = None ,
7575 ) -> None :
7676 """
7777 Authenticates user, saves credentials to a file and generates api token.
@@ -96,7 +96,7 @@ def __init__(
9696 self .authenticate (session_builder .login_credentials )
9797
9898 @staticmethod
99- def from_file (auth : OAuth , cred_file : Path | str , language : str = "en" ) -> Session :
99+ def from_file (cred_file : Path | str , language : str = "en" ) -> Session :
100100 """
101101 Creates session using saved credentials file
102102 Args:
@@ -107,17 +107,17 @@ def from_file(auth: OAuth, cred_file: Path | str, language: str = "en") -> Sessi
107107 """
108108 if not isinstance (cred_file , Path ):
109109 cred_file = Path (cred_file ).expanduser ()
110- conf = (
110+ config = (
111111 LibrespotSession .Configuration .Builder ()
112112 .set_store_credentials (False )
113113 .build ()
114114 )
115- session = LibrespotSession .Builder (conf ).stored_file (str (cred_file ))
116- return Session (session , auth , language ) # TODO
115+ session = LibrespotSession .Builder (config ).stored_file (str (cred_file ))
116+ return Session (session , language )
117117
118118 @staticmethod
119119 def from_oauth (
120- auth : OAuth ,
120+ oauth : OAuth ,
121121 save_file : Path | str | None = None ,
122122 language : str = "en" ,
123123 ) -> Session :
@@ -129,24 +129,24 @@ def from_oauth(
129129 Returns:
130130 Zotify session
131131 """
132- builder = LibrespotSession .Configuration .Builder ()
132+ config = LibrespotSession .Configuration .Builder ()
133133 if save_file :
134134 if not isinstance (save_file , Path ):
135135 save_file = Path (save_file ).expanduser ()
136136 save_file .parent .mkdir (parents = True , exist_ok = True )
137- builder .set_stored_credential_file (str (save_file ))
137+ config .set_stored_credential_file (str (save_file ))
138138 else :
139- builder .set_store_credentials (False )
139+ config .set_store_credentials (False )
140140
141- token = auth .await_token ()
141+ token = oauth .await_token ()
142142
143- session = LibrespotSession .Builder (builder .build ())
144- session .login_credentials = Authentication .LoginCredentials (
145- username = auth .username ,
143+ builder = LibrespotSession .Builder (config .build ())
144+ builder .login_credentials = Authentication .LoginCredentials (
145+ username = oauth .username ,
146146 typ = Authentication .AuthenticationType .values ()[3 ],
147147 auth_data = token .access_token .encode (),
148148 )
149- return Session (session , auth , language )
149+ return Session (builder , language , oauth )
150150
151151 def __get_playable (
152152 self , playable_id : PlayableId , quality : Quality
@@ -186,7 +186,7 @@ def get_episode(self, episode_id: str) -> Episode:
186186 self .api (),
187187 )
188188
189- def oauth (self ) -> OAuth :
189+ def oauth (self ) -> OAuth | None :
190190 """Returns OAuth service"""
191191 return self .__oauth
192192
@@ -282,7 +282,10 @@ def __init__(self, session: Session):
282282 self ._session = session
283283
284284 def get_token (self , * scopes ) -> TokenProvider .StoredToken :
285- return self ._session .oauth ().get_token ()
285+ oauth = self ._session .oauth ()
286+ if oauth is None :
287+ return super ().get_token (* scopes )
288+ return oauth .get_token ()
286289
287290 class StoredToken (LibrespotTokenProvider .StoredToken ):
288291 def __init__ (self , obj ):
@@ -301,15 +304,15 @@ class OAuth:
301304
302305 def __init__ (self , username : str ):
303306 self .username = username
304- self .__server_thread = Thread (target = self .__run_server )
305- self .__server_thread .start ()
306307
307- def get_authorization_url (self ) -> str :
308+ def auth_interactive (self ) -> str :
308309 """
309- Generate OAuth URL
310+ Starts local server for token callback
310311 Returns:
311312 OAuth URL
312313 """
314+ self .__server_thread = Thread (target = self .__run_server )
315+ self .__server_thread .start ()
313316 self .__code_verifier = generate_code_verifier ()
314317 code_challenge = get_code_challenge (self .__code_verifier )
315318 params = {
0 commit comments