diff --git a/plextraktsync/config/HttpCacheConfig.py b/plextraktsync/config/HttpCacheConfig.py index 1fdb0ee27a..6f81f64d79 100644 --- a/plextraktsync/config/HttpCacheConfig.py +++ b/plextraktsync/config/HttpCacheConfig.py @@ -76,7 +76,7 @@ class HttpCacheConfig: "plex.tv/api/v2/user": "1m", # Plex patterns # Ratings search - "*/library/sections/*/all?*userRating%3E%3E=-1*": DO_NOT_CACHE, + "*/library/sections/*/all?*userRating%3E%3E=-1*": "1m", # len(PlexLibrarySection) "*/library/sections/*/all?includeCollections=0&X-Plex-Container-Size=0&X-Plex-Container-Start=0": DO_NOT_CACHE, # __iter__(PlexLibrarySection) diff --git a/plextraktsync/media/Media.py b/plextraktsync/media/Media.py index 9b852ba18c..748873e322 100644 --- a/plextraktsync/media/Media.py +++ b/plextraktsync/media/Media.py @@ -225,11 +225,7 @@ def trakt_rating(self): @cached_property def plex_rating(self): - if self.media_type == "episodes" and not self.plex.is_discover and self.show: - show_id = self.show.plex.item.ratingKey - else: - show_id = None - return self.plex.rating(show_id) + return self.plex.rating() def trakt_rate(self): rating = self.plex_rating diff --git a/plextraktsync/plex/PlexLibraryItem.py b/plextraktsync/plex/PlexLibraryItem.py index 12602e0e80..3fb6b9dbf3 100644 --- a/plextraktsync/plex/PlexLibraryItem.py +++ b/plextraktsync/plex/PlexLibraryItem.py @@ -155,9 +155,9 @@ def title(self): return value - def rating(self, show_id: int = None): + def rating(self): if not self.is_discover and self.plex is not None: - return self.plex.ratings.get(self, show_id) + return self.plex.ratings.get(self) return Rating.create(self.item.userRating, self.item.lastRatedAt) diff --git a/plextraktsync/plex/PlexRatings.py b/plextraktsync/plex/PlexRatings.py index 6857e65385..70799fe969 100644 --- a/plextraktsync/plex/PlexRatings.py +++ b/plextraktsync/plex/PlexRatings.py @@ -25,25 +25,13 @@ def get(self, m: PlexLibraryItem, show_id: int = None): # this can happen when doing "inspect" if section_id not in self.plex.library_sections: return None + if m.media_type not in ["movies", "shows", "episodes"]: + raise RuntimeError(f"Unsupported media type: {m.media_type}") - media_type = m.media_type section = self.plex.library_sections[section_id] - ratings: dict[int, Rating] = self.ratings(section, media_type) + ratings: dict[int, Rating] = self.ratings(section, m.media_type) - if media_type in ["movies", "shows"]: - # For movies and shows, just return from the dict - if m.item.ratingKey in ratings: - return ratings[m.item.ratingKey] - elif media_type == "episodes": - # For episodes the ratings is just (show_id, show_rating) tuples - # if show id is not listed, return none, otherwise fetch from item itself - if show_id not in ratings: - return None - return Rating.create(m.item.userRating, m.item.lastRatedAt) - else: - raise RuntimeError(f"Unsupported media type: {media_type}") - - return None + return ratings.get(m.item.ratingKey, None) @staticmethod @memoize @@ -54,6 +42,11 @@ def ratings(section: PlexLibrarySection, media_type: str): "episodes": "episode.userRating", "shows": "show.userRating", }[media_type] + libtype = { + "movies": "movie", + "episodes": "episode", + "shows": "show", + }[media_type] filters = { "and": [ @@ -61,5 +54,5 @@ def ratings(section: PlexLibrarySection, media_type: str): ] } - for item in section.search(filters=filters, includeGuids=False): + for item in section.search(filters=filters, libtype=libtype, includeGuids=False): yield item.ratingKey, Rating.create(item.userRating, item.lastRatedAt)