From 83418d6f8095a0c74c16f20c7598d63e5841237c Mon Sep 17 00:00:00 2001 From: davidemarcoli Date: Fri, 22 Nov 2024 11:04:44 +0100 Subject: [PATCH] fix: consolidate User-Agent header usage in Torrentio scraper --- src/program/services/scrapers/torrentio.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/program/services/scrapers/torrentio.py b/src/program/services/scrapers/torrentio.py index 566867bf..128c20c9 100644 --- a/src/program/services/scrapers/torrentio.py +++ b/src/program/services/scrapers/torrentio.py @@ -28,6 +28,7 @@ def __init__(self): rate_limit_params = get_rate_limit_params(max_calls=1, period=5) if self.settings.ratelimit else None session = create_service_session(rate_limit_params=rate_limit_params) self.request_handler = ScraperRequestHandler(session) + self.headers = {"User-Agent": "Mozilla/5.0"} self.initialized: bool = self.validate() if not self.initialized: return @@ -45,8 +46,7 @@ def validate(self) -> bool: return False try: url = f"{self.settings.url}/{self.settings.filter}/manifest.json" - headers = {"User-Agent": "Mozilla/5.0"} - response = self.request_handler.execute(HttpMethod.GET, url, timeout=10, headers=headers) + response = self.request_handler.execute(HttpMethod.GET, url, timeout=10, headers=self.headers) if response.is_ok: return True except Exception as e: @@ -74,7 +74,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) + response = self.request_handler.execute(HttpMethod.GET, f"{url}.json", timeout=self.timeout, headers=self.headers) 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 {}