Skip to content

Commit

Permalink
fix: consolidate User-Agent header usage in Torrentio scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
davidemarcoli authored and dreulavelle committed Nov 22, 2024
1 parent bb799b5 commit 83418d6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/program/services/scrapers/torrentio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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 {}
Expand Down

0 comments on commit 83418d6

Please sign in to comment.