Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plex: Use username for watch key if exists #240

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -300,8 +302,7 @@ 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_name, user_plex, library) -> LibraryData:
try:
logger.info(
f"Plex: Generating watched for {user_name} in library {library.title}",
Expand Down Expand Up @@ -388,22 +389,24 @@ 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:
if library.title not in sync_libraries:
continue

library_data = self.get_user_library_watched(
user, user_plex, library
user_name, user_plex, library
)

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:
Expand Down
Loading