From c52df7c5eec866acc8d8f4c8cfcd847450abc586 Mon Sep 17 00:00:00 2001 From: blacktwin Date: Fri, 27 Jan 2023 10:44:15 -0500 Subject: [PATCH] Adding batching method to find all watched content. Fixes #368 --- utility/sync_watch_status.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/utility/sync_watch_status.py b/utility/sync_watch_status.py index 9f3fad0..3fa4ca7 100644 --- a/utility/sync_watch_status.py +++ b/utility/sync_watch_status.py @@ -407,6 +407,30 @@ def sync_watch_status(watched, section, accountTo, userTo, same_server=False): pass +def batching_watched(section, libtype): + count = 100 + start = 0 + watched_lst = [] + while True: + + if libtype == 'show': + search_watched = section.search(libtype='episode', container_start=start, container_size=count, + **{'show.unwatchedLeaves': False}) + else: + search_watched = section.search(unwatched=False, container_start=start, container_size=count) + if all([search_watched]): + start += count + for item in search_watched: + if item not in watched_lst: + watched_lst.append(item) + continue + elif not all([search_watched]): + break + start += count + + return watched_lst + + if __name__ == '__main__': parser = argparse.ArgumentParser(description="Sync watch status from one user to others.", formatter_class=argparse.RawTextHelpFormatter) @@ -498,10 +522,7 @@ if __name__ == '__main__': else: # Check library for watched items sectionFrom = watchedFrom.library.section(_library.title) - if _library.type == 'show': - watched_lst = sectionFrom.search(libtype='episode', **{'show.unwatchedLeaves': False}) - else: - watched_lst = sectionFrom.search(unwatched=False) + watched_lst = batching_watched(sectionFrom, _library.type) for user in plexTo: username, server = user