From 428dbe6ba2dc4cf9d346604176f7f9e701bcff54 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 28 Feb 2024 15:40:17 -0500 Subject: [PATCH] [31] update playlist fixes --- VERSION | 2 +- modules/builder.py | 33 ++++++++++++--------------------- modules/plex.py | 17 ++++++----------- plex_meta_manager.py | 4 +--- requirements.txt | 8 ++++---- 5 files changed, 24 insertions(+), 40 deletions(-) diff --git a/VERSION b/VERSION index d2bd24a7..e0838e56 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.20.0-develop30 +1.20.0-develop31 diff --git a/modules/builder.py b/modules/builder.py index 54f9afdb..87d5e281 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -530,10 +530,7 @@ class CollectionBuilder: self.exclude_users = config.general["playlist_exclude_users"] logger.warning(f"Playlist Warning: exclude_users attribute not found defaulting to playlist_exclude_users: {self.exclude_users}") - plex_admin = self.library.account.username - _plex_users = self.library.users - plex_users = _plex_users.copy() - plex_users.append(plex_admin) + plex_users = self.library.users + [self.library.account.username] self.exclude_users = util.get_list(self.exclude_users) if self.exclude_users else [] for user in self.exclude_users: @@ -556,8 +553,7 @@ class CollectionBuilder: logger.debug("Validating Method: delete_playlist") logger.debug(f"Value: {data[methods['delete_playlist']]}") if util.parse(self.Type, "delete_playlist", self.data, datatype="bool", methods=methods, default=False): - playlist_getters = [self.library.get_playlist, self.library.get_playlist_from_users] - for getter in playlist_getters: + for getter in [self.library.get_playlist, self.library.get_playlist_from_users]: try: self.obj = getter(self.name) break @@ -2130,7 +2126,7 @@ class CollectionBuilder: final_method = "trakt_chart" if method_name != final_method: logger.warning(f"{self.Type} Warning: {method_name} will run as {final_method}") - for trakt_dict in self.config.Trakt.validate_chart(self.Type, final_method, trakt_dicts, self.library.is_movie): + for trakt_dict in self.config.Trakt.validate_chart(self.Type, final_method, trakt_dicts, self.library.is_movie): self.builders.append((final_method, trakt_dict)) def _tvdb(self, method_name, method_data): @@ -3544,19 +3540,15 @@ class CollectionBuilder: if self.playlist: for user in self.valid_users: - if user == self.library.account.username: - try: + try: + if user == self.library.account.username: _ = self.library.get_playlist(title) # Verify if this playlist exists in Admin to avoid log confusion self.library.delete(self.obj) - output += f"\nPlaylist deleted on {user}" - except Failed: - output += f"\nPlaylist not found on {user}" - else: - try: + else: self.library.delete_user_playlist(title, user) - output += f"\nPlaylist deleted on User {user}" - except Failed: - output += f"\nPlaylist not found on User {user}" + output += f"\nPlaylist deleted on User {user}" + except Failed: + output += f"\nPlaylist not found on User {user}" elif self.obj: self.library.delete(self.obj) return output @@ -3572,8 +3564,7 @@ class CollectionBuilder: except Failed: pass if user != self.library.account.username: - new_playlist = self.obj.copyToUser(user) - new_playlist = new_playlist.editSummary(summary=self.summaries["summary"]).reload() + self.obj.copyToUser(user).editSummary(summary=self.obj.summary).reload() logger.info(f"Playlist: {self.name} synced to {user}") def exclude_admin_from_playlist(self): @@ -3583,9 +3574,9 @@ class CollectionBuilder: logger.info("") try: self.library.delete(self.obj) - logger.info(f"Playlist: {self.name} deleted on {self.library.account.username}") + logger.info(f"Playlist: {self.name} deleted on User {self.library.account.username}") except Failed: - logger.info(f"Playlist: {self.name} not found on {self.library.account.username}") + logger.info(f"Playlist: {self.name} not found on User {self.library.account.username}") def send_notifications(self, playlist=False): if self.obj and self.details["changes_webhooks"] and \ diff --git a/modules/plex.py b/modules/plex.py index 1d7a32e8..f6922cb0 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -1004,20 +1004,15 @@ class Plex(Library): except NotFound: raise Failed(f"Plex Error: Playlist {title} not found") - def get_playlist_from_users(self, title): - def scan_user(server, title): + def get_playlist_from_users(self, playlist_title): + for user in self.users: try: - for playlist in server.playlists(): - if isinstance(playlist, Playlist): - if playlist.title == title: - return playlist + for playlist in self.PlexServer.switchUser(user).playlists(): + if isinstance(playlist, Playlist) and playlist.title == playlist_title: + return playlist except requests.exceptions.ConnectionError: pass - for user in self.users: - playlist_obj = scan_user(self.PlexServer.switchUser(user), title) - if playlist_obj: - return playlist_obj - raise Failed(f"Plex Error: Playlist {title} not found") + raise Failed(f"Plex Error: Playlist {playlist_title} not found") def get_collection(self, data, force_search=False, debug=True): if isinstance(data, Collection): diff --git a/plex_meta_manager.py b/plex_meta_manager.py index e4b5a23e..29e8f952 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -1043,12 +1043,10 @@ def run_playlists(config): if valid: builder.sync_playlist() + builder.exclude_admin_from_playlist() builder.send_notifications(playlist=True) - if valid: - builder.exclude_admin_from_playlist() - except Deleted as e: logger.info(e) status[mapping_name]["status"] = "Deleted" diff --git a/requirements.txt b/requirements.txt index b834187a..e94a5f1a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ arrapi==1.4.7 -GitPython==3.1.41 +GitPython==3.1.42 lxml==5.1.0 num2words==0.5.13 pathvalidate==3.2.0 pillow==10.2.0 -PlexAPI==4.15.9 +PlexAPI==4.15.10 psutil==5.9.8 python-dotenv==1.0.1 python-dateutil==2.8.2 @@ -12,5 +12,5 @@ requests==2.31.0 retrying==1.3.4 ruamel.yaml==0.18.6 schedule==1.2.1 -setuptools==69.1.0 -tmdbapis==1.2.6 \ No newline at end of file +setuptools==69.1.1 +tmdbapis==1.2.7 \ No newline at end of file