Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions zotify/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ def ensure_uri(item: dict | None, type_attr_and_ind: str):
if not uri: uri = f":local:{type_attr_and_ind.lower()}:{name}:::"
item[URI] = uri

def unknown_user(owner_username: str | None) -> dict | None:
if not owner_username: return None
return { URI : f":{USER}:{owner_username}",
def unknown_user(username: str | None) -> dict | None:
if not username: return None
display_name = Zotify.get_user_display_name(username)
return { URI : f":{USER}:{username}",
TYPE: USER,
DISPLAY_NAME: owner_username }
DISPLAY_NAME: display_name }

activity_period : list[dict] = resp.get(ACTIVITY_PERIOD)
if activity_period:
Expand Down Expand Up @@ -1305,7 +1306,7 @@ class User(Container):
_contains = Playlist
def __init__(self, uri: str):
super().__init__(uri)
self.display_name : str = None # will be id if not permit_client_api()
self.display_name : str = None
self.external_urls : dict = None


Expand Down
26 changes: 21 additions & 5 deletions zotify/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,18 +644,20 @@ class Zotify:
DOWNLOAD_BITRATE : str = None

# DYNAMICS
TOTAL_API_CALLS : int = None
DATETIME_LAUNCH : str = None
LEGACY_API_ENDOINTS : bool = True
FORCE_LIBRE_METADATA : bool = False
FORCE_STREAM_API_CALLS : bool = False
TOTAL_API_CALLS : int = None
DATETIME_LAUNCH : str = None
LEGACY_API_ENDOINTS : bool = True
FORCE_LIBRE_METADATA : bool = False
FORCE_STREAM_API_CALLS : bool = False
USER_DISPLAY_NAME_MAP : dict[str, str] = None

@classmethod
def start(cls) -> None:
if cls.TOTAL_API_CALLS:
Printer.debug(f"Total API Calls: {cls.TOTAL_API_CALLS}")
cls.DATETIME_LAUNCH = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
cls.TOTAL_API_CALLS = 0
cls.USER_DISPLAY_NAME_MAP = {}

@classmethod
def login(cls, args):
Expand Down Expand Up @@ -784,6 +786,20 @@ def id_from_gid(gid: str) -> str:
@staticmethod
def hex_id_from_file_id(file_id: str) -> str:
return hexlify(b64decode(file_id.encode())).decode()

@staticmethod
def get_user_display_name(username: str) -> str:
try:
display_name = Zotify.USER_DISPLAY_NAME_MAP.get(username)
if not display_name:
user_profile = Zotify.SESSION.api().get_user_profile(username, 0, 0)
display_name = user_profile[NAME]
Zotify.USER_DISPLAY_NAME_MAP[username] = display_name
return display_name
except Exception as e:
Printer.debug(f"Failed to fetch display name for {username}")
Printer.traceback(e)
return {}

@staticmethod
def to_libre_content(ContClass: type, uri: str) -> metadata.Id | None:
Expand Down