Skip to content

Commit

Permalink
fix: tweaked comet scraper. removed poetry venv from entrypoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Jul 25, 2024
1 parent 0ae2bcf commit 32be8fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
1 change: 0 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export HOME="$USER_HOME"
# Ensure poetry is in the PATH
export PATH="$PATH:/app/.venv/bin"

poetry config virtualenvs.create false
echo "Container Initialization complete."

echo "Starting Riven (Backend)..."
Expand Down
43 changes: 19 additions & 24 deletions src/program/scrapers/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import json
from typing import Dict, Union

import regex

from program.media.item import Episode, MediaItem, Movie, Season, Show
from program.settings.manager import settings_manager
from requests import ConnectTimeout, ReadTimeout
Expand All @@ -20,13 +22,12 @@ def __init__(self):
self.timeout = self.settings.timeout
self.encoded_string = base64.b64encode(json.dumps({
"indexers": self.settings.indexers,
"maxResults":0,
"filterTitles":False,
"resolutions":["All"],
"languages":["All"],
"debridService":"realdebrid",
"maxResults": 0,
"resolutions": ["All"],
"languages": ["All"],
"debridService": "realdebrid",
"debridApiKey": settings_manager.settings.downloaders.real_debrid.api_key,
"debridStreamProxyPassword":""
"debridStreamProxyPassword": ""
}).encode("utf-8")).decode("utf-8")
self.initialized = self.validate()
if not self.initialized:
Expand Down Expand Up @@ -55,13 +56,12 @@ def validate(self) -> bool:
return True
except Exception as e:
logger.error(f"Comet failed to initialize: {e}", )
return False
return True
return False

def run(self, item: MediaItem) -> Dict[str, str]:
"""Scrape the comet site for the given media items
and update the object with scraped streams"""
if not item:
if not item or isinstance(item, Show):
return {}

try:
Expand Down Expand Up @@ -125,28 +125,23 @@ def api_scrape(self, item: MediaItem) -> tuple[Dict[str, str], int]:
else:
response = get(url, timeout=self.timeout)

if not response.is_ok or not response.data.streams:
if not response.is_ok or not getattr(response.data, "streams", None):
return {}, 0

torrents: Dict[str, str] = {}
for stream in response.data.streams:
# Split the URL by '/playback/' and then split the remaining part by '/'

url_parts = stream.url.split("/playback/")

if len(url_parts) != 2:
logger.warning(f"Comet Playback url can't be parsed: {stream.url}")

end_parts = url_parts[1].split("/")

if len(end_parts) != 2:
logger.warning(f"End part of Comet Playback url can't be parsed ({end_parts}): {stream.url}")
if stream.title == "Invalid Comet config.":
logger.error("Invalid Comet config.")
return {}, 0

hash = end_parts[0]
infohash_pattern = regex.compile(r"(?!.*playback\/)[a-zA-Z0-9]{40}")
infohash = infohash_pattern.search(stream.url).group()
title = stream.title.split("\n")[0]

if not hash:
if not infohash:
logger.warning(f"Comet infohash not found for title: {title}")
continue

torrents[hash] = stream.title
torrents[infohash] = title

return torrents, len(response.data.streams)

0 comments on commit 32be8fc

Please sign in to comment.