From 82b9ca93c669c0139a7fdb65104bba9d9fc3ac33 Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Wed, 26 Feb 2025 00:38:10 +0000 Subject: [PATCH] Plex: Use username for watch key if exists Signed-off-by: Luis Garcia --- src/plex.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/plex.py b/src/plex.py index 315686b..745e3ac 100644 --- a/src/plex.py +++ b/src/plex.py @@ -281,7 +281,9 @@ def get_libraries(self) -> dict[str, str]: output = {} libraries = self.plex.library.sections() - logger.debug(f"Plex: All Libraries {[library.title for library in libraries]}") + logger.debug( + f"Plex: All Libraries {[library.title for library in libraries]}" + ) for library in libraries: library_title = library.title @@ -300,8 +302,9 @@ def get_libraries(self) -> dict[str, str]: logger.error(f"Plex: Failed to get libraries, Error: {e}") raise Exception(e) - def get_user_library_watched(self, user, user_plex, library) -> LibraryData: - user_name: str = user.username.lower() if user.username else user.title.lower() + def get_user_library_watched( + self, user, user_plex, library, user_name + ) -> LibraryData: try: logger.info( f"Plex: Generating watched for {user_name} in library {library.title}", @@ -388,6 +391,10 @@ def get_watched(self, users, sync_libraries) -> dict[str, UserData]: ) continue + user_name: str = ( + user.username.lower() if user.username else user.title.lower() + ) + libraries = user_plex.library.sections() for library in libraries: @@ -395,15 +402,13 @@ def get_watched(self, users, sync_libraries) -> dict[str, UserData]: continue library_data = self.get_user_library_watched( - user, user_plex, library + user, user_plex, library, user_name ) - if user.title.lower() not in users_watched: - users_watched[user.title.lower()] = UserData() + if user_name not in users_watched: + users_watched[user_name] = UserData() - users_watched[user.title.lower()].libraries[library.title] = ( - library_data - ) + users_watched[user_name].libraries[library.title] = library_data return users_watched except Exception as e: