Skip to content

Commit

Permalink
feat: add proxy_url to torrentio (#994)
Browse files Browse the repository at this point in the history
* feat: add proxy_url to torrentio

* fix: remove extra logging

* chore: add to .env.example
  • Loading branch information
AyushSehrawat authored Feb 9, 2025
1 parent 2eb98ca commit d1ad6fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# using the env variables you specified.
RIVEN_FORCE_ENV=false

# This is used to specify settings filename. By default it's settings.json.
RIVEN_SETTINGS_FILENAME="settings.json"

# This will reset the database and recreate all tables, and then exit after running!
HARD_RESET=false

Expand All @@ -18,7 +21,7 @@ REPAIR_SYMLINKS=false
# Manual api key, must be 32 characters long
API_KEY=1234567890qwertyuiopas

# This is the number of workers to use for reindexing symlinks after a database reset.
# This is the number of workers to use for reindexing symlinks after a database reset.
# More workers = faster symlinking but uses more memory.
# For lower end machines, stick to around 1-3.
# For higher end machines, you can do as many as you want, or set it to the number of cores.
Expand Down Expand Up @@ -118,6 +121,7 @@ RIVEN_SCRAPING_TORRENTIO_FILTER=sort=qualitysize%7Cqualityfilter=480p,scr,cam
RIVEN_SCRAPING_TORRENTIO_URL=http://torrentio.strem.fun
RIVEN_SCRAPING_TORRENTIO_TIMEOUT=30
RIVEN_SCRAPING_TORRENTIO_RATELIMIT=true
RIVEN_SCRAPING_TORRENTIO_PROXY_URL=
RIVEN_SCRAPING_KNIGHTCRAWLER_ENABLED=false
RIVEN_SCRAPING_KNIGHTCRAWLER_FILTER=sort=qualitysize%7Cqualityfilter=480p,scr,cam
RIVEN_SCRAPING_KNIGHTCRAWLER_URL=https://knightcrawler.elfhosted.com
Expand All @@ -139,7 +143,7 @@ RIVEN_SCRAPING_ORIONOID_API_KEY=
RIVEN_SCRAPING_ORIONOID_CACHED_RESULTS_ONLY=false
RIVEN_SCRAPING_ORIONOID_PARAMETERS_VIDEO3D=false # See the Orionoid API docs for more information on these parameters.
RIVEN_SCRAPING_ORIONOID_PARAMETERS_VIDEOQUALITY=sd_hd8k # See the Orionoid API docs for more information on these parameters.
RIVEN_SCRAPING_ORIONOID_PARAMETERS_LIMITCOUNT=5 # See the Orionoid API docs for more information on these parameters.
RIVEN_SCRAPING_ORIONOID_PARAMETERS_LIMITCOUNT=5 # See the Orionoid API docs for more information on these parameters.
RIVEN_SCRAPING_ORIONOID_TIMEOUT=30
RIVEN_SCRAPING_ORIONOID_RATELIMIT=true
RIVEN_SCRAPING_MEDIAFUSION_ENABLED=false
Expand Down Expand Up @@ -344,4 +348,4 @@ RIVEN_LOGGER_API_ICON=👾
RIVEN_LOGGER_PLEX_FG=DAD3BE
RIVEN_LOGGER_PLEX_ICON=📽️
RIVEN_LOGGER_TRAKT_FG=1DB954
RIVEN_LOGGER_TRAKT_ICON=🎵
RIVEN_LOGGER_TRAKT_ICON=🎵
7 changes: 4 additions & 3 deletions src/program/services/scrapers/torrentio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self):
session = create_service_session(rate_limit_params=rate_limit_params)
self.request_handler = ScraperRequestHandler(session)
self.headers = {"User-Agent": "Mozilla/5.0"}
self.proxies = {"http": self.settings.proxy_url, "https": self.settings.proxy_url} if self.settings.proxy_url else None
self.initialized: bool = self.validate()
if not self.initialized:
return
Expand All @@ -46,7 +47,7 @@ def validate(self) -> bool:
return False
try:
url = f"{self.settings.url}/{self.settings.filter}/manifest.json"
response = self.request_handler.execute(HttpMethod.GET, url, timeout=10, headers=self.headers)
response = self.request_handler.execute(HttpMethod.GET, url, timeout=10, headers=self.headers, proxies=self.proxies)
if response.is_ok:
return True
except Exception as e:
Expand Down Expand Up @@ -74,7 +75,7 @@ def scrape(self, item: MediaItem) -> tuple[Dict[str, str], int]:
if identifier:
url += identifier

response = self.request_handler.execute(HttpMethod.GET, f"{url}.json", timeout=self.timeout, headers=self.headers)
response = self.request_handler.execute(HttpMethod.GET, f"{url}.json", timeout=self.timeout, headers=self.headers, proxies=self.proxies)
if not response.is_ok or not hasattr(response.data, 'streams') or not response.data.streams:
logger.log("NOT_FOUND", f"No streams found for {item.log_string}")
return {}
Expand All @@ -93,4 +94,4 @@ def scrape(self, item: MediaItem) -> tuple[Dict[str, str], int]:
else:
logger.log("NOT_FOUND", f"No streams found for {item.log_string}")

return torrents
return torrents
1 change: 1 addition & 0 deletions src/program/settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class TorrentioConfig(Observable):
url: str = "http://torrentio.strem.fun"
timeout: int = 30
ratelimit: bool = Field(default=True, deprecated=deprecation_warning)
proxy_url: str = ""


class KnightcrawlerConfig(Observable):
Expand Down

0 comments on commit d1ad6fd

Please sign in to comment.