Pass max_length to items() and all() rather the odd hack
MODIFY
plex_trakt_sync/plex_api.py
plex_trakt_sync/plex_api.py
@@ -355,7 +355,6 @@ class PlexLibrarySection:
def __init__(self, section: LibrarySection):
self.section = section
- @memoize
@nocache
def __len__(self):
return self.section.totalSize
@@ -364,12 +363,11 @@ def __len__(self):
def title(self):
return self.section.title
- def all(self):
+ def all(self, max_items: int):
libtype = self.section.TYPE
key = self.section._buildSearchKey(libtype=libtype, returnKwargs=False)
start = 0
size = X_PLEX_CONTAINER_SIZE
- length = len(self)
while True:
items = self.fetch_items(key, size, start)
@@ -379,18 +377,15 @@ def all(self):
yield from items
start += size
- if start > length:
+ if start > max_items:
break
- # clear cached value for next call to all() to be accurate if library changes
- self.__len__.cache_clear()
-
@nocache
def fetch_items(self, key: str, size: int, start: int):
return self.section.fetchItems(key, container_start=start, container_size=size)
- def items(self):
- for item in (PlexLibraryItem(x) for x in self.all()):
+ def items(self, max_items: int):
+ for item in (PlexLibraryItem(x) for x in self.all(max_items)):
yield item

MODIFY
plex_trakt_sync/walker.py
plex_trakt_sync/walker.py
from plex_trakt_sync.decorators.measure_time import measure_time
from plex_trakt_sync.media import MediaFactory, Media
-from plex_trakt_sync.plex_api import PlexApi
+from plex_trakt_sync.plex_api import PlexApi, PlexLibrarySection
class Walker:
@@ -91,14 +91,15 @@ def find_episodes(self):
continue
yield from self.episode_from_show(show)
- def media_from_sections(self, sections, titles: List[str]):
+ def media_from_sections(self, sections: List[PlexLibrarySection], titles: List[str]):
if titles:
# Filter by matching section names
sections = [x for x in sections if x.title in titles]
for section in sections:
with measure_time(f"{section.title} processed"):
- it = self.progressbar(section.items(), total=len(section), desc=f"Processing {section.title}")
+ total = len(section)
+ it = self.progressbar(section.items(total), total=total, desc=f"Processing {section.title}")
yield from it
def media_from_titles(self, libtype: str, titles: List[str]):

Pass max_length to items() and all() rather the odd hack