Skip to content

Commit

Permalink
fix: fixed comet unpack issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Oct 3, 2024
1 parent bef6056 commit 6ae2a68
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
16 changes: 0 additions & 16 deletions src/controllers/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from fastapi import APIRouter, HTTPException, Request
from sqlalchemy import select
from program.scrapers import Scraping
from program.db.db_functions import get_item_by_imdb_id
from program.indexers.trakt import TraktIndexer
from program.media.item import MediaItem
from program.downloaders.realdebrid import get_torrents
from program.db.db import db

router = APIRouter(
Expand Down Expand Up @@ -78,17 +76,3 @@ async def scrape(request: Request, imdb_id: str, season: int = None, episode: in
raise HTTPException(status_code=500, detail=str(e))

return {"success": True, "data": data}


@router.get(
"/rd",
summary="Get Real-Debrid Torrents",
description="Get torrents from Real-Debrid."
)
async def get_rd_torrents(limit: int = 1000):
"""
Get torrents from Real-Debrid.
- **limit**: Limit the number of torrents to get.
"""
return get_torrents(limit)
1 change: 0 additions & 1 deletion src/controllers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from fastapi import APIRouter, HTTPException
from pydantic import BaseModel, ValidationError
from RTN.models import SettingsModel

from program.settings.manager import settings_manager

Expand Down
7 changes: 5 additions & 2 deletions src/program/content/plex_watchlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from plexapi.myplex import MyPlexAccount
from requests import HTTPError, Session
from urllib3 import HTTPConnectionPool

from program.db.db_functions import _filter_existing_items
from program.media.item import Episode, MediaItem, Movie, Season, Show
Expand Down Expand Up @@ -64,7 +65,7 @@ def run(self) -> Generator[MediaItem, None, None]:
watchlist_items: list[str] = self._get_items_from_watchlist()
rss_items: list[str] = self._get_items_from_rss() if self.rss_enabled else []
except Exception as e:
logger.error(f"Error fetching items: {e}")
logger.warning(f"Error fetching items: {e}")
return

plex_items: set[str] = set(watchlist_items) | set(rss_items)
Expand All @@ -88,6 +89,7 @@ def _get_items_from_rss(self) -> list[str]:
imdb_id = self._extract_imdb_ids(_item.get("guids", []))
if imdb_id and imdb_id.startswith("tt"):
rss_items.append(imdb_id)
self.recurring_items.add(imdb_id)
else:
logger.log("NOT_FOUND", f"Failed to extract IMDb ID from {_item['title']}")
except Exception as e:
Expand All @@ -104,12 +106,13 @@ def _get_items_from_watchlist(self) -> list[str]:
imdb_id: str = next((guid.id.split("//")[-1] for guid in item.guids if guid.id.startswith("imdb://")), "")
if imdb_id and imdb_id.startswith("tt"):
watchlist_items.append(imdb_id)
self.recurring_items.add(imdb_id)
else:
logger.log("NOT_FOUND", f"Unable to extract IMDb ID from {item.title} ({item.year}) with data id: {imdb_id}")
else:
logger.log("NOT_FOUND", f"{item.title} ({item.year}) is missing guids attribute from Plex")
except Exception as e:
logger.error(f"An unexpected error occurred while fetching Plex watchlist item {item.log_string}: {e}")
logger.error(f"An unexpected error occurred while fetching Plex watchlist item {item.title}: {e}")
return watchlist_items

def _extract_imdb_ids(self, guids: list) -> str | None:
Expand Down
11 changes: 1 addition & 10 deletions src/program/scrapers/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,7 @@ def run(self, item: MediaItem) -> Dict[str, str]:
logger.error(f"Comet exception thrown: {str(e)}")
return {}

def scrape(self, item: MediaItem) -> Dict[str, str]:
"""Scrape the given media item"""
data, stream_count = self.api_scrape(item)
if data:
logger.log("SCRAPER", f"Found {len(data)} streams out of {stream_count} for {item.log_string}")
else:
logger.log("NOT_FOUND", f"No streams found for {item.log_string}")
return data

def api_scrape(self, item: MediaItem) -> tuple[Dict[str, str], int]:
def scrape(self, item: MediaItem) -> tuple[Dict[str, str], int]:
"""Wrapper for `Comet` scrape method"""
identifier, scrape_type, imdb_id = _get_stremio_identifier(item)
if not imdb_id:
Expand Down

0 comments on commit 6ae2a68

Please sign in to comment.