From 9a2a0c14211f68af523af4cdb3c8f742496a7722 Mon Sep 17 00:00:00 2001 From: Spoked Date: Sat, 21 Sep 2024 07:42:57 -0400 Subject: [PATCH] fix: plex rss startswith error --- src/program/content/plex_watchlist.py | 8 ++++---- src/program/indexers/trakt.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/program/content/plex_watchlist.py b/src/program/content/plex_watchlist.py index ce787af7..3adac1c9 100644 --- a/src/program/content/plex_watchlist.py +++ b/src/program/content/plex_watchlist.py @@ -68,7 +68,7 @@ def run(self) -> Generator[MediaItem, None, None]: return plex_items: set[str] = set(watchlist_items) | set(rss_items) - items_to_yield: list[MediaItem] = [MediaItem({"imdb_id": imdb_id, "requested_by": self.key}) for imdb_id in plex_items if imdb_id.startswith("tt")] + items_to_yield: list[MediaItem] = [MediaItem({"imdb_id": imdb_id, "requested_by": self.key}) for imdb_id in plex_items if imdb_id and imdb_id.startswith("tt")] non_existing_items = _filter_existing_items(items_to_yield) new_non_recurring_items = [item for item in non_existing_items if item.imdb_id not in self.recurring_items and isinstance(item, MediaItem)] self.recurring_items.update([item.imdb_id for item in new_non_recurring_items]) @@ -86,7 +86,7 @@ def _get_items_from_rss(self) -> list[str]: response = self.session.get(rss_url + "?format=json", timeout=60) for _item in response.json().get("items", []): imdb_id = self._extract_imdb_ids(_item.get("guids", [])) - if imdb_id.startswith("tt"): + if imdb_id and imdb_id.startswith("tt"): rss_items.append(imdb_id) else: logger.log("NOT_FOUND", f"Failed to extract IMDb ID from {_item['title']}") @@ -102,7 +102,7 @@ def _get_items_from_watchlist(self) -> list[str]: try: if hasattr(item, "guids") and item.guids: imdb_id: str = next((guid.id.split("//")[-1] for guid in item.guids if guid.id.startswith("imdb://")), "") - if imdb_id.startswith("tt"): + if imdb_id and imdb_id.startswith("tt"): watchlist_items.append(imdb_id) else: logger.log("NOT_FOUND", f"Unable to extract IMDb ID from {item.title} ({item.year}) with data id: {imdb_id}") @@ -115,7 +115,7 @@ def _get_items_from_watchlist(self) -> list[str]: def _extract_imdb_ids(self, guids: list) -> str | None: """Helper method to extract IMDb IDs from guids""" for guid in guids: - if guid.startswith("imdb://"): + if guid and guid.startswith("imdb://"): imdb_id = guid.split("//")[-1] if imdb_id: return imdb_id diff --git a/src/program/indexers/trakt.py b/src/program/indexers/trakt.py index 51dbf8a9..33c75e81 100644 --- a/src/program/indexers/trakt.py +++ b/src/program/indexers/trakt.py @@ -196,7 +196,7 @@ def get_show_aliases(imdb_id: str, item_type: str) -> List[dict]: for ns in response.data: country = ns.country title = ns.title - if title.startswith("Anime-"): + if title and title.startswith("Anime-"): title = title[len("Anime-"):] if country not in aliases: aliases[country] = []