diff --git a/librespot/audio/__init__.py b/librespot/audio/__init__.py index 577c4c5..0ac4ec4 100644 --- a/librespot/audio/__init__.py +++ b/librespot/audio/__init__.py @@ -77,6 +77,24 @@ def _spoticlub_notify_session_done() -> None: ) atexit.register(_spoticlub_notify_session_done) + +def _get_zotify_config_dir() -> Path: + # Fix OS paths not being consistent + if os.name == "nt": + appdata = os.environ.get("APPDATA") + if appdata: + return Path(appdata) / "Zotify" + return Path.home() / "AppData" / "Roaming" / "Zotify" + + xdg_config_home = os.environ.get("XDG_CONFIG_HOME") + if xdg_config_home: + return Path(xdg_config_home) / "zotify" + return Path.home() / ".config" / "zotify" + + +def _get_spoticlub_credentials_path() -> Path: + return _get_zotify_config_dir() / "spoticlub_credentials.json" + ######################################## class LoadedStream(GeneralAudioStream): @@ -399,13 +417,13 @@ class AudioKeyManager(PacketsReceiver, Closeable): _attempt=_attempt + 1, ) - self.logger.error( - "Giving up fetching audio key from Spotify after %d attempts; gid=%s fileId=%s (last error: %s)", - _attempt, - util.bytes_to_hex(gid), - util.bytes_to_hex(file_id), - last_err, - ) + # self.logger.error( + # "Giving up fetching audio key from Spotify after %d attempts; gid=%s fileId=%s (last error: %s)", + # _attempt, + # util.bytes_to_hex(gid), + # util.bytes_to_hex(file_id), + # last_err, + # ) raise RuntimeError( "Failed fetching Audio Key from Spotify for gid: {}, fileId: {} (last error: {})".format( util.bytes_to_hex(gid), @@ -427,12 +445,12 @@ class AudioKeyManager(PacketsReceiver, Closeable): try: return self._get_spotify_audio_key(gid, file_id, retry=retry) except Exception as exc: # noqa: BLE001 - self.logger.warning( - "Spotify audio key fetch failed for premium user; falling back to SpotiClub API: %s", - exc, - ) + #self.logger.warning( + # "Spotify audio key fetch failed for premium user; falling back to SpotiClub API: %s", + # exc, + #) print( - "\n[Warning] Spotify refused or failed to provide the audio key for this track." + "\n[Warning] Spotify refused or failed to provide the audio key for this track. " "Falling back to SpotiClub API...\n" ) @@ -440,7 +458,7 @@ class AudioKeyManager(PacketsReceiver, Closeable): if not spoticlub_user or not spoticlub_password or spoticlub_user == "anonymous": try: # To verify : Do all forks look for the same path ? - cfg_path = Path.home() / "AppData\\Roaming\\Zotify\\spoticlub_credentials.json" + cfg_path = _get_spoticlub_credentials_path() if cfg_path.is_file(): print(f"\n[SpotiClub API] Loading credentials...") with open(cfg_path, "r", encoding="utf-8") as f: @@ -453,7 +471,7 @@ class AudioKeyManager(PacketsReceiver, Closeable): print(f"[SpotiClub API] Error while loading credentials file: {exc}\n") if not spoticlub_user or not spoticlub_password or not server_url: - cfg_path = Path.home() / "AppData\\Roaming\\Zotify\\spoticlub_credentials.json" + cfg_path = _get_spoticlub_credentials_path() msg = ( "Missing SpotiClub credentials: please set the appropriates values inside your spoticlub_credentials.json," f"located in the Zotify config folder [{cfg_path}] (Or delete it and restart Zotify to be prompted for credentials)."