Skip to content

Commit 66e98dc

Browse files
author
Zotify
committed
fix selection printing
1 parent 77ba1cb commit 66e98dc

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

zotify/__init__.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

231225
class 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

zotify/app.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from typing import Any
44

5-
from zotify import Session
5+
from zotify import OAuth, Session
66
from zotify.collections import Album, Artist, Collection, Episode, Playlist, Show, Track
77
from zotify.config import Config
88
from zotify.file import TranscodingError
@@ -80,7 +80,9 @@ def get(self, category: str, name: str = "", content: str = "") -> list[str]:
8080
except KeyError:
8181
item = resp[i]
8282
self.__items.append(item)
83-
self.__print(i + 1, item)
83+
print(
84+
"{:<2} {:<38}".format(i + 1, self.__fix_string_length(item["name"], 38))
85+
)
8486
return self.__get_selection()
8587

8688
@staticmethod
@@ -162,8 +164,12 @@ def __init__(self, args: Namespace):
162164
# self.__session = Session.from_prompt(
163165
# self.__config.credentials_path, self.__config.language
164166
# )
167+
username = input("Username: ")
168+
auth = OAuth(username)
169+
auth_url = auth.get_authorization_url()
170+
print(f"\nClick on the following link to login:\n{auth_url}")
165171
self.__session = Session.from_oauth(
166-
self.__config.credentials_path, self.__config.language
172+
auth, self.__config.credentials_path, self.__config.language
167173
)
168174

169175
# Get items to download

0 commit comments

Comments
 (0)