Remove sleep config, fetch IP to check VPN status. Refactor IP swap to function.

This commit is contained in:
Tyler Flowers 2026-03-22 16:32:01 -04:00 committed by GitHub
parent 9880b1d4fb
commit eec617a610
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 62 deletions

View File

@ -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()

View File

@ -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,

View File

@ -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

View File

@ -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;

View File

@ -76,8 +76,7 @@ const SettingsApplication = () => {
const [gluetunControlUrl, setGluetunControlUrl] = useState<string | null>(null);
const [gluetunControlKey, setGluetunControlKey] = useState<string | null>(null);
const [gluetunSwap, setGluetunSwap] = useState<boolean>(false);
const [gluetunAttempts, setGluetunAttempts] = useState<number | null>(null);
const [gluetunSleep, setGluetunSleep] = useState<number | null>(null);
const [gluetunAttempts, setGluetunAttempts] = useState<number | null>(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.
</li>
<li>
Setting "Sleep Interval" will wait that amount of time after
swapping the IP before attempting to download again. Default is 30.
</li>
</ul>
</div>
)}
@ -875,19 +869,6 @@ const SettingsApplication = () => {
updateCallback={handleUpdateConfig}
/>
</div>
<div className="settings-box-wrapper">
<div>
<p>Sleep Interval</p>
</div>
<InputConfig
type="number"
name="downloads.gluetun_sleep"
value={gluetunSleep}
setValue={setGluetunSleep}
oldValue={appSettingsConfig?.downloads.gluetun_sleep}
updateCallback={handleUpdateConfig}
/>
</div>
</div>
<div className="info-box-item">
<h2 id="sntegrations">Integrations</h2>

View File

@ -35,7 +35,6 @@ export const useAppSettingsStore = create<AppSettingsState>(set => ({
gluetun_control_key: null,
gluetun_swap: false,
gluetun_attempts: null,
gluetun_sleep: null,
throttledratelimit: null,
extractor_lang: null,
integrate_ryd: false,