fix selection printing

This commit is contained in:
Zotify 2024-08-17 01:59:24 +12:00
parent 77ba1cba9c
commit 66e98dc98d
2 changed files with 18 additions and 16 deletions

View File

@ -96,7 +96,7 @@ class Session(LibrespotSession):
self.authenticate(session_builder.login_credentials)
@staticmethod
def from_file(cred_file: Path | str, language: str = "en") -> Session:
def from_file(auth: OAuth, cred_file: Path | str, language: str = "en") -> Session:
"""
Creates session using saved credentials file
Args:
@ -113,11 +113,13 @@ class Session(LibrespotSession):
.build()
)
session = LibrespotSession.Builder(conf).stored_file(str(cred_file))
return Session(session, OAuth(), language) # TODO
return Session(session, auth, language) # TODO
@staticmethod
def from_oauth(
save_file: Path | str | None = None, language: str = "en"
auth: OAuth,
save_file: Path | str | None = None,
language: str = "en",
) -> Session:
"""
Creates a session using OAuth2
@ -136,15 +138,11 @@ class Session(LibrespotSession):
else:
builder.set_store_credentials(False)
# TODO: this should be done in App()
username = input("Username: ")
auth = OAuth()
print(f"Click on the following link to login:\n{auth.get_authorization_url()}")
token = auth.await_token()
session = LibrespotSession.Builder(builder.build())
session.login_credentials = Authentication.LoginCredentials(
username=username,
username=auth.username,
typ=Authentication.AuthenticationType.values()[3],
auth_data=token.access_token.encode(),
)
@ -221,11 +219,7 @@ class Session(LibrespotSession):
self.__event_service = EventService(self)
self.__auth_lock_bool = False
self.__auth_lock.notify_all()
self.dealer().connect()
self.mercury().interested_in("sp" + "otify:user:attributes:update", self)
self.dealer().add_message_listener(
self, ["hm://connect-state/v1/connect/logout"]
)
class ApiClient(LibrespotApiClient):
@ -303,8 +297,10 @@ class OAuth:
__code_verifier: str
__server_thread: Thread
__token: TokenProvider.StoredToken
username: str
def __init__(self):
def __init__(self, username: str):
self.username = username
self.__server_thread = Thread(target=self.__run_server)
self.__server_thread.start()

View File

@ -2,7 +2,7 @@ from argparse import Namespace
from pathlib import Path
from typing import Any
from zotify import Session
from zotify import OAuth, Session
from zotify.collections import Album, Artist, Collection, Episode, Playlist, Show, Track
from zotify.config import Config
from zotify.file import TranscodingError
@ -80,7 +80,9 @@ class Selection:
except KeyError:
item = resp[i]
self.__items.append(item)
self.__print(i + 1, item)
print(
"{:<2} {:<38}".format(i + 1, self.__fix_string_length(item["name"], 38))
)
return self.__get_selection()
@staticmethod
@ -162,8 +164,12 @@ class App:
# self.__session = Session.from_prompt(
# self.__config.credentials_path, self.__config.language
# )
username = input("Username: ")
auth = OAuth(username)
auth_url = auth.get_authorization_url()
print(f"\nClick on the following link to login:\n{auth_url}")
self.__session = Session.from_oauth(
self.__config.credentials_path, self.__config.language
auth, self.__config.credentials_path, self.__config.language
)
# Get items to download