Fix print loader issue
Some checks failed
CodeQL / Analyze (python) (push) Has been cancelled

This commit is contained in:
unknown
2025-12-19 02:16:24 +01:00
parent 6d3b159099
commit 36d08aae85

View File

@@ -51,6 +51,9 @@ spoticlub_password = "IfWeFeelLikeEnablingThis"
### SPOTICLUB CLIENT SERIAL TRACKING (DO NOT EDIT) ###
spoticlub_client_serial: typing.Optional[str] = None
spoticlub_loaded_logged: bool = False
_spoticlub_audio_key_loader_enabled: bool = False
_spoticlub_audio_key_loader_lock = threading.Lock()
########################################
def _spoticlub_notify_session_done() -> None:
global spoticlub_user, spoticlub_password, spoticlub_client_serial
@@ -71,7 +74,6 @@ def _spoticlub_notify_session_done() -> None:
exc_info=True,
)
atexit.register(_spoticlub_notify_session_done)
########################################
@@ -442,7 +444,10 @@ class AudioKeyManager(PacketsReceiver, Closeable):
try:
from zotify.loader import Loader
from zotify.termoutput import PrintChannel
audio_key_loader = Loader(PrintChannel.PROGRESS_INFO, "Fetching audio key...").start()
with _spoticlub_audio_key_loader_lock:
show_loader = _spoticlub_audio_key_loader_enabled
if show_loader:
audio_key_loader = Loader(PrintChannel.PROGRESS_INFO, "Fetching audio key...").start()
except Exception:
audio_key_loader = None
@@ -488,7 +493,7 @@ class AudioKeyManager(PacketsReceiver, Closeable):
if isinstance(country, str):
if AudioKeyManager._spoticlub_current_country != country:
AudioKeyManager._spoticlub_current_country = country
print(f"\n[SpotiClub API] Received {country} as the download country\n")
print(f"\n\n[SpotiClub API] Received {country} as the download country\n\n")
new_serial = data.get("client_serial")
if isinstance(new_serial, str) and new_serial:
@@ -497,6 +502,10 @@ class AudioKeyManager(PacketsReceiver, Closeable):
key_bytes = util.hex_to_bytes(key_hex)
if len(key_bytes) != 16:
raise RuntimeError("[SpotiClub API] Woops, received Audio Key must be 16 bytes long")
# After the first successful SpotiClub key fetch, enable the loader for future calls.
with _spoticlub_audio_key_loader_lock:
_spoticlub_audio_key_loader_enabled = True
return key_bytes
except Exception as exc: # noqa: BLE001
last_err = exc