Skip to content

Commit

Permalink
fix: moved downloader proxy settings to parent instead of per debrid
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Nov 27, 2024
1 parent 602f732 commit 50d9d6e
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 27 deletions.
6 changes: 1 addition & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=

Expand Down
1 change: 0 additions & 1 deletion src/program/services/downloaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 1 addition & 4 deletions src/program/services/downloaders/alldebrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/program/services/downloaders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)


Expand Down
5 changes: 1 addition & 4 deletions src/program/services/downloaders/realdebrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/program/services/downloaders/shared.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/program/services/downloaders/torbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 1 addition & 7 deletions src/program/settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/routers/secure/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit 50d9d6e

Please sign in to comment.