From a5585bf34626ecc7759c0a4d56b9dc4012055d7a Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 6 Jun 2023 10:35:55 -0400 Subject: [PATCH] [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: