From 645be0def3c14745585fdcb3afa1171f3daffeaf Mon Sep 17 00:00:00 2001 From: DraftKinner <196864209+DraftKinner@users.noreply.github.com> Date: Mon, 10 Feb 2025 00:27:17 -0500 Subject: [PATCH] Fixed issue #4 (Audio key error, code: 2) --- requirements.txt | 1 + setup.cfg | 1 + zotify/__init__.py | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/requirements.txt b/requirements.txt index 4634246..67f7dfa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ Pillow pkce requests tqdm +ratelimit diff --git a/setup.cfg b/setup.cfg index c9cc896..5393bf2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,6 +26,7 @@ install_requires = pkce requests tqdm + ratelimit [options.entry_points] console_scripts = diff --git a/zotify/__init__.py b/zotify/__init__.py index 9f95e53..673155b 100644 --- a/zotify/__init__.py +++ b/zotify/__init__.py @@ -7,6 +7,7 @@ from threading import Thread from typing import Any from time import time_ns from urllib.parse import urlencode, urlparse, parse_qs +from ratelimit import limits, sleep_and_retry from librespot.audio import AudioKeyManager, CdnManager from librespot.audio.decoders import VorbisOnlyAudioQuality @@ -36,6 +37,8 @@ API_URL = "https://api.sp" + "otify.com/v1/" AUTH_URL = "https://accounts.sp" + "otify.com/" REDIRECT_URI = "http://127.0.0.1:4381/login" CLIENT_ID = "65b70807" + "3fc0480e" + "a92a0772" + "33ca87bd" +RATE_LIMIT_INTERVAL_SECS = 30 +RATE_LIMIT_CALLS_PER_INTERVAL = 9 SCOPES = [ "app-remote-control", "playlist-modify", @@ -221,6 +224,11 @@ class Session(LibrespotSession): self.__auth_lock.notify_all() self.mercury().interested_in("sp" + "otify:user:attributes:update", self) + @sleep_and_retry + @limits(calls=RATE_LIMIT_CALLS_PER_INTERVAL, period=RATE_LIMIT_INTERVAL_SECS) + def api(self) -> ApiClient: + return super().api() + class ApiClient(LibrespotApiClient): def __init__(self, session: Session):