From 50d9d6eb5e37912beff765f7bf753cf08486216b Mon Sep 17 00:00:00 2001 From: Spoked Date: Tue, 26 Nov 2024 23:37:17 -0500 Subject: [PATCH] fix: moved downloader proxy settings to parent instead of per debrid --- .env.example | 6 +----- src/program/services/downloaders/__init__.py | 1 - src/program/services/downloaders/alldebrid.py | 5 +---- src/program/services/downloaders/models.py | 4 ++-- src/program/services/downloaders/realdebrid.py | 5 +---- src/program/services/downloaders/shared.py | 4 +++- src/program/services/downloaders/torbox.py | 2 +- src/program/settings/models.py | 8 +------- src/routers/secure/default.py | 4 ++-- 9 files changed, 12 insertions(+), 27 deletions(-) diff --git a/.env.example b/.env.example index 9f371e97..2ea86720 100644 --- a/.env.example +++ b/.env.example @@ -66,15 +66,11 @@ RIVEN_EMBY_URL=http://localhost:8096 #------------------------------------- RIVEN_DOWNLOADERS_VIDEO_EXTENSIONS=["mp4","mkv","avi"] -RIVEN_DOWNLOADERS_PREFER_SPEED_OVER_QUALITY=false +RIVEN_DOWNLOADERS_PROXY_URL= RIVEN_DOWNLOADERS_REAL_DEBRID_ENABLED=false RIVEN_DOWNLOADERS_REAL_DEBRID_API_KEY= -RIVEN_DOWNLOADERS_REAL_DEBRID_PROXY_ENABLED=false -RIVEN_DOWNLOADERS_REAL_DEBRID_PROXY_URL= RIVEN_DOWNLOADERS_ALL_DEBRID_ENABLED=false RIVEN_DOWNLOADERS_ALL_DEBRID_API_KEY= -RIVEN_DOWNLOADERS_ALL_DEBRID_PROXY_ENABLED=false -RIVEN_DOWNLOADERS_ALL_DEBRID_PROXY_URL= RIVEN_DOWNLOADERS_TORBOX_ENABLED=false RIVEN_DOWNLOADERS_TORBOX_API_KEY= diff --git a/src/program/services/downloaders/__init__.py b/src/program/services/downloaders/__init__.py index 7993baac..48f1d194 100644 --- a/src/program/services/downloaders/__init__.py +++ b/src/program/services/downloaders/__init__.py @@ -26,7 +26,6 @@ class Downloader: def __init__(self): self.key = "downloader" self.initialized = False - self.speed_mode = settings_manager.settings.downloaders.prefer_speed_over_quality self.services = { RealDebridDownloader: RealDebridDownloader(), TorBoxDownloader: TorBoxDownloader(), diff --git a/src/program/services/downloaders/alldebrid.py b/src/program/services/downloaders/alldebrid.py index 136b62e2..bef99af3 100644 --- a/src/program/services/downloaders/alldebrid.py +++ b/src/program/services/downloaders/alldebrid.py @@ -80,7 +80,7 @@ def validate(self) -> bool: self.api = AllDebridAPI( api_key=self.settings.api_key, - proxy_url=self.settings.proxy_url if self.settings.proxy_enabled else None + proxy_url=self.PROXY_URL if self.PROXY_URL else None ) if not self._validate_premium(): @@ -96,9 +96,6 @@ def _validate_settings(self) -> bool: if not self.settings.api_key: logger.warning("AllDebrid API key is not set") return False - if self.settings.proxy_enabled and not self.settings.proxy_url: - logger.error("Proxy is enabled but no proxy URL is provided") - return False return True def _validate_premium(self) -> bool: diff --git a/src/program/services/downloaders/models.py b/src/program/services/downloaders/models.py index d7703010..c90dbe97 100644 --- a/src/program/services/downloaders/models.py +++ b/src/program/services/downloaders/models.py @@ -25,11 +25,11 @@ # constraints for filesizes, follows the format tuple(min, max) FILESIZE_MOVIE_CONSTRAINT: tuple[int, int] = ( movie_min_filesize if movie_min_filesize >= 0 else 0, - movie_max_filesize if movie_max_filesize >= 0 else float("inf") + movie_max_filesize if movie_max_filesize > 0 else float("inf") ) FILESIZE_EPISODE_CONSTRAINT: tuple[int, int] = ( episode_min_filesize if episode_min_filesize >= 0 else 0, - episode_max_filesize if episode_max_filesize >= 0 else float("inf") + episode_max_filesize if episode_max_filesize > 0 else float("inf") ) diff --git a/src/program/services/downloaders/realdebrid.py b/src/program/services/downloaders/realdebrid.py index 1472b43d..a5ae6fec 100644 --- a/src/program/services/downloaders/realdebrid.py +++ b/src/program/services/downloaders/realdebrid.py @@ -98,7 +98,7 @@ def validate(self) -> bool: self.api = RealDebridAPI( api_key=self.settings.api_key, - proxy_url=self.settings.proxy_url if self.settings.proxy_enabled else None + proxy_url=self.PROXY_URL if self.PROXY_URL else None ) return self._validate_premium() @@ -110,9 +110,6 @@ def _validate_settings(self) -> bool: if not self.settings.api_key: logger.warning("Real-Debrid API key is not set") return False - if self.settings.proxy_enabled and not self.settings.proxy_url: - logger.error("Proxy is enabled but no proxy URL is provided") - return False return True def _validate_premium(self) -> bool: diff --git a/src/program/services/downloaders/shared.py b/src/program/services/downloaders/shared.py index abb3e60c..c71ee9f4 100644 --- a/src/program/services/downloaders/shared.py +++ b/src/program/services/downloaders/shared.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod from datetime import datetime -from typing import List, Optional +from typing import Optional from RTN import ParsedData, parse @@ -9,10 +9,12 @@ TorrentContainer, TorrentInfo, ) +from program.settings.manager import settings_manager class DownloaderBase(ABC): """The abstract base class for all Downloader implementations.""" + PROXY_URL: str = settings_manager.settings.downloaders.proxy_url @abstractmethod def validate(self) -> bool: diff --git a/src/program/services/downloaders/torbox.py b/src/program/services/downloaders/torbox.py index 2e08b77f..f12fa614 100644 --- a/src/program/services/downloaders/torbox.py +++ b/src/program/services/downloaders/torbox.py @@ -84,7 +84,7 @@ def validate(self) -> bool: self.api = TorBoxAPI( api_key=self.settings.api_key, - proxy_url=self.settings.proxy_url if self.settings.proxy_enabled else None + proxy_url=self.PROXY_URL if self.PROXY_URL else None ) return self._validate_premium() diff --git a/src/program/settings/models.py b/src/program/settings/models.py index d9f1a73b..d0c8e17c 100644 --- a/src/program/settings/models.py +++ b/src/program/settings/models.py @@ -43,31 +43,25 @@ def __exit__(self_, exc_type, exc_value, traceback): class RealDebridModel(Observable): enabled: bool = False api_key: str = "" - proxy_enabled: bool = False - proxy_url: str = "" class AllDebridModel(Observable): enabled: bool = False api_key: str = "" - proxy_enabled: bool = False - proxy_url: str = "" class TorboxModel(Observable): enabled: bool = False api_key: str = "" - proxy_enabled: bool = False - proxy_url: str = "" class DownloadersModel(Observable): video_extensions: List[str] = ["mp4", "mkv", "avi"] - prefer_speed_over_quality: bool = True movie_filesize_mb_min: int = 0 # MB movie_filesize_mb_max: int = -1 # MB (-1 is no limit) episode_filesize_mb_min: int = 0 # MB episode_filesize_mb_max: int = -1 # MB (-1 is no limit) + proxy_url: str = "" real_debrid: RealDebridModel = RealDebridModel() all_debrid: AllDebridModel = AllDebridModel() torbox: TorboxModel = TorboxModel() diff --git a/src/routers/secure/default.py b/src/routers/secure/default.py index 8be9e8d7..8575955f 100644 --- a/src/routers/secure/default.py +++ b/src/routers/secure/default.py @@ -46,8 +46,8 @@ async def get_rd_user() -> RDUser: headers = {"Authorization": f"Bearer {api_key}"} proxy = ( - settings_manager.settings.downloaders.real_debrid.proxy_url - if settings_manager.settings.downloaders.real_debrid.proxy_enabled + settings_manager.settings.downloaders.proxy_url + if settings_manager.settings.downloaders.proxy_url else None )