From a5585bf34626ecc7759c0a4d56b9dc4012055d7a Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jun 2023 10:35:55 -0400 Subject: [PATCH 1/2] [65] fix library load --- VERSION | 2 +- modules/plex.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 07126381..f7f48a2b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.19.0-develop64 +1.19.0-develop65 diff --git a/modules/plex.py b/modules/plex.py index 3c9f5ad9..076c81b8 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -540,11 +540,22 @@ class Plex(Library): container_start = 0 container_size = plexapi.X_PLEX_CONTAINER_SIZE results = [] - while self.Plex._totalViewSize is None or container_start <= self.Plex._totalViewSize: - results.extend(self.fetchItems(key, container_start, container_size)) - logger.ghost(f"Loaded: {container_start}/{self.Plex._totalViewSize}") + total_size = 1 + while total_size > len(results) and container_start <= total_size: + data = self.Plex._server.query(key, headers={"X-Plex-Container-Start": str(container_start), "X-Plex-Container-Size": str(container_size)}) + subresults = self.Plex.findItems(data, initpath=key) + total_size = utils.cast(int, data.attrib.get('totalSize') or data.attrib.get('size')) or len(subresults) + + librarySectionID = utils.cast(int, data.attrib.get('librarySectionID')) + if librarySectionID: + for item in subresults: + item.librarySectionID = librarySectionID + + results.extend(subresults) container_start += container_size - logger.info(f"Loaded {self.Plex._totalViewSize} {builder_level.capitalize()}s") + logger.ghost(f"Loaded: {total_size if container_start > total_size else container_start}/{total_size}") + + logger.info(f"Loaded {total_size} {builder_level.capitalize()}s") if builder_level in [None, "show", "artist", "movie"]: self._all_items = results return results @@ -560,10 +571,6 @@ class Plex(Library): def create_playlist(self, name, items): return self.PlexServer.createPlaylist(name, items=items) - @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) - def fetchItems(self, key, container_start, container_size): - return self.Plex.fetchItems(key, container_start=container_start, container_size=container_size) - @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) def moveItem(self, obj, item, after): try: From 84c754587314b6e1c5aa9b6b0eb816cacbc79920 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jun 2023 10:57:40 -0400 Subject: [PATCH 2/2] [66] fix filter items --- VERSION | 2 +- modules/builder.py | 4 ++-- modules/plex.py | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index f7f48a2b..dff0f99e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.19.0-develop65 +1.19.0-develop66 diff --git a/modules/builder.py b/modules/builder.py index e00990a8..41f77f78 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -1123,7 +1123,7 @@ class CollectionBuilder: if self.obj and check_url != self.library.smart_filter(self.obj): self.library.update_smart_collection(self.obj, check_url) logger.info(f"Detail: Smart Collection updated to {check_url}") - self.beginning_count = len(self.library.get_filter_items(check_url)) + self.beginning_count = len(self.library.fetchItems(check_url)) if self.obj: self.exists = True if self.sync or self.playlist: @@ -3159,7 +3159,7 @@ class CollectionBuilder: raise else: raise Failed(str(e)) - items = self.library.get_filter_items(search_data[2]) + items = self.library.fetchItems(search_data[2]) previous = None sort_edit = False for i, item in enumerate(items, 0): diff --git a/modules/plex.py b/modules/plex.py index 076c81b8..7533ae6a 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -496,7 +496,7 @@ class Plex(Library): args = f"{args}&label={label_id}" else: return [] - return self.get_filter_items(args) + return self.fetchItems(args) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) def search(self, title=None, sort=None, maxresults=None, libtype=None, **kwargs): @@ -527,6 +527,10 @@ class Plex(Library): def fetchItem(self, data): return self.PlexServer.fetchItem(data) + @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) + def fetchItems(self, uri_args): + return self.Plex.fetchItems(f"/library/sections/{self.Plex.key}/all{uri_args}") + def get_all(self, builder_level=None, load=False): if load and builder_level in [None, "show", "artist", "movie"]: self._all_items = [] @@ -865,7 +869,7 @@ class Plex(Library): def test_smart_filter(self, uri_args): logger.debug(f"Smart Collection Test: {uri_args}") - test_items = self.get_filter_items(uri_args) + test_items = self.fetchItems(uri_args) if len(test_items) < 1: raise Failed(f"Plex Error: No items for smart filter: {uri_args}") @@ -1035,7 +1039,7 @@ class Plex(Library): elif method == "plex_search": logger.info(f"Processing {data[1]}") logger.trace(data[2]) - items = self.get_filter_items(data[2]) + items = self.fetchItems(data[2]) elif method == "plex_collectionless": good_collections = [] logger.info(f"Processing Plex Collectionless") @@ -1084,16 +1088,12 @@ class Plex(Library): return self.search(label=collection.title if isinstance(collection, Collection) else str(collection)) elif isinstance(collection, (Collection, Playlist)): if collection.smart: - return self.get_filter_items(self.smart_filter(collection)) + return self.fetchItems(self.smart_filter(collection)) else: return self.query(collection.items) else: return [] - def get_filter_items(self, uri_args): - key = f"/library/sections/{self.Plex.key}/all{uri_args}" - return self.Plex._search(key, None, 0, plexapi.X_PLEX_CONTAINER_SIZE) - def get_collection_name_and_items(self, collection, smart_label_collection): name = collection.title if isinstance(collection, (Collection, Playlist)) else str(collection) return name, self.get_collection_items(collection, smart_label_collection)