diff --git a/backend/appsettings/serializers.py b/backend/appsettings/serializers.py index f42e01bf..9a38b928 100644 --- a/backend/appsettings/serializers.py +++ b/backend/appsettings/serializers.py @@ -60,7 +60,6 @@ class AppConfigDownloadsSerializer( gluetun_control_key = serializers.CharField(allow_null=True) gluetun_swap = serializers.BooleanField() gluetun_attempts = serializers.IntegerField(allow_null=True) - gluetun_sleep = serializers.IntegerField(allow_null=True) throttledratelimit = serializers.IntegerField(allow_null=True) extractor_lang = serializers.CharField(allow_null=True) integrate_ryd = serializers.BooleanField() diff --git a/backend/appsettings/src/config.py b/backend/appsettings/src/config.py index 5264199c..a3d5d3d6 100644 --- a/backend/appsettings/src/config.py +++ b/backend/appsettings/src/config.py @@ -98,7 +98,6 @@ class AppConfig: "gluetun_control_key": None, "gluetun_swap": False, "gluetun_attempts": 0, - "gluetun_sleep": 0, "throttledratelimit": None, "extractor_lang": None, "integrate_ryd": False, diff --git a/backend/download/src/yt_dlp_base.py b/backend/download/src/yt_dlp_base.py index 0b1f76ce..c5b866c1 100644 --- a/backend/download/src/yt_dlp_base.py +++ b/backend/download/src/yt_dlp_base.py @@ -89,6 +89,39 @@ class YtWrap: "proxy": [proxy_url] }, ) + + def _swap_ip(self): + control_url = self.config['downloads'].get('gluetun_control_url') + headers = { + "Content-Type": "application/json", + "X-API-Key": self.config['downloads'].get('gluetun_control_key') + } + requests.put( + url = control_url + "/v1/vpn/status", + headers = headers, + json = {"status": "stopped"} + ) + requests.put( + url = control_url + "/v1/vpn/status", + headers = headers, + json = {"status": "running"} + ) + swap_attempt = 0 + while swap_attempt < 5: + time.sleep(10) + try: + res = requests.get( + url = control_url + "/v1/publicip/ip", + headers = headers + ) + if (res.text == ""): + raise ConnectionError("Gluetun has not connected to VPN yet") + break + except: + swap_attempt += 1 + if (swap_attempt == 5): + raise ConnectionError("Gluetun could not connect to VPN!") + def download(self, url): """make download request""" @@ -111,28 +144,10 @@ class YtWrap: if any(m in str(err) for m in self.BOT_MESSAGES): print(self.BOT_ERROR_LOG) if self.config["downloads"].get("gluetun_swap"): - control_url=f"{self.config['downloads'].get('gluetun_control_url')}/v1/vpn/status" - headers={ - "Content-Type": "application/json", - "X-API-Key": self.config['downloads'].get('gluetun_control_key') - } - requests.put( - url=control_url, - headers=headers, - json={"status": "stopped"} - ) - requests.put( - url=control_url, - headers=headers, - json={"status": "running"} - ) - sleep_amount = self.config['downloads'].get('gluetun_sleep') - if sleep_amount == 0: - sleep_amount = 30 - time.sleep(sleep_amount) attempt += 1 if (attempt == max_attempts): raise ConnectionError("Reached maximum IP attempts!") from err + self._swap_ip() continue rand_sleep(self.config) raise ConnectionError(self.BOT_ERROR_LOG) from err @@ -175,28 +190,10 @@ class YtWrap: if any(m in str(err) for m in self.BOT_MESSAGES): print(self.BOT_ERROR_LOG) if self.config["downloads"].get("gluetun_swap"): - control_url=f"{self.config['downloads'].get('gluetun_control_url')}/v1/vpn/status" - headers={ - "Content-Type": "application/json", - "X-API-Key": self.config['downloads'].get('gluetun_control_key') - } - requests.put( - url=control_url, - headers=headers, - json={"status": "stopped"} - ) - requests.put( - url=control_url, - headers=headers, - json={"status": "running"} - ) - sleep_amount = self.config['downloads'].get('gluetun_sleep') - if sleep_amount == 0: - sleep_amount = 30 - time.sleep(sleep_amount) attempt += 1 if (attempt == max_attempts): raise ConnectionError("Reached maximum IP attempts!") from err + self._swap_ip() continue rand_sleep(self.config) raise ConnectionError(self.BOT_ERROR_LOG) from err diff --git a/frontend/src/api/loader/loadAppsettingsConfig.ts b/frontend/src/api/loader/loadAppsettingsConfig.ts index 1b3d6f8b..70dfe576 100644 --- a/frontend/src/api/loader/loadAppsettingsConfig.ts +++ b/frontend/src/api/loader/loadAppsettingsConfig.ts @@ -28,7 +28,6 @@ export type AppSettingsConfigType = { gluetun_control_key: string | null; gluetun_swap: boolean; gluetun_attempts: number | null; - gluetun_sleep: number | null; throttledratelimit: number | null; extractor_lang: string | null; integrate_ryd: boolean; diff --git a/frontend/src/pages/SettingsApplication.tsx b/frontend/src/pages/SettingsApplication.tsx index bdb2290d..5692fcce 100644 --- a/frontend/src/pages/SettingsApplication.tsx +++ b/frontend/src/pages/SettingsApplication.tsx @@ -76,8 +76,7 @@ const SettingsApplication = () => { const [gluetunControlUrl, setGluetunControlUrl] = useState(null); const [gluetunControlKey, setGluetunControlKey] = useState(null); const [gluetunSwap, setGluetunSwap] = useState(false); - const [gluetunAttempts, setGluetunAttempts] = useState(null); - const [gluetunSleep, setGluetunSleep] = useState(null); + const [gluetunAttempts, setGluetunAttempts] = useState(null) // Integrations const [showApiToken, setShowApiToken] = useState(false); @@ -139,7 +138,6 @@ const SettingsApplication = () => { setGluetunControlKey(appSettingsConfigData?.downloads.gluetun_control_key || null); setGluetunSwap(appSettingsConfigData?.downloads.gluetun_swap || false); setGluetunAttempts(appSettingsConfigData?.downloads.gluetun_attempts || null); - setGluetunSleep(appSettingsConfigData?.downloads.gluetun_sleep || null); // Integrations setDownloadDislikes(appSettingsConfigData?.downloads.integrate_ryd || false); @@ -806,10 +804,6 @@ const SettingsApplication = () => { swapping the IP infinitely until it can download. Otherwise, it will attempt to swap the IP only for a certain number of attempts. -
  • - Setting "Sleep Interval" will wait that amount of time after - swapping the IP before attempting to download again. Default is 30. -
  • )} @@ -875,19 +869,6 @@ const SettingsApplication = () => { updateCallback={handleUpdateConfig} /> -
    -
    -

    Sleep Interval

    -
    - -

    Integrations

    diff --git a/frontend/src/stores/AppSettingsStore.ts b/frontend/src/stores/AppSettingsStore.ts index 1d8a017f..3691f27f 100644 --- a/frontend/src/stores/AppSettingsStore.ts +++ b/frontend/src/stores/AppSettingsStore.ts @@ -35,7 +35,6 @@ export const useAppSettingsStore = create(set => ({ gluetun_control_key: null, gluetun_swap: false, gluetun_attempts: null, - gluetun_sleep: null, throttledratelimit: null, extractor_lang: null, integrate_ryd: false,