Skip to content

Commit

Permalink
fix: plex rss startswith error
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Sep 21, 2024
1 parent 12f4a1a commit 9a2a0c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/program/content/plex_watchlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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']}")
Expand All @@ -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}")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/program/indexers/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down

0 comments on commit 9a2a0c1

Please sign in to comment.