mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2024-11-29 07:50:24 +00:00
[3] fix deleting playlists
This commit is contained in:
parent
3e8cb33a83
commit
e64c56f4f2
5 changed files with 33 additions and 16 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.17.0-develop2
|
||||
1.17.0-develop3
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import os, re, time
|
||||
from datetime import datetime
|
||||
from modules import anidb, anilist, flixpatrol, icheckmovies, imdb, letterboxd, mal, plex, radarr, reciperr, sonarr, tautulli, tmdb, trakt, tvdb, mdblist, util
|
||||
from modules.util import Failed, NotScheduled, NotScheduledRange, Overlay
|
||||
from modules.util import Failed, NotScheduled, NotScheduledRange, Overlay, Deleted
|
||||
from plexapi.audio import Artist, Album, Track
|
||||
from plexapi.exceptions import BadRequest, NotFound
|
||||
from plexapi.video import Movie, Show, Season, Episode
|
||||
|
@ -293,7 +293,7 @@ class CollectionBuilder:
|
|||
logger.debug(f"Value: {data[methods['delete_playlist']]}")
|
||||
if util.parse(self.Type, "delete_playlist", self.data, datatype="bool", methods=methods, default=False):
|
||||
self.obj = self.library.get_playlist(self.name)
|
||||
logger.info(self.delete())
|
||||
raise Deleted(self.delete())
|
||||
else:
|
||||
self.libraries.append(self.library)
|
||||
|
||||
|
@ -2576,18 +2576,23 @@ class CollectionBuilder:
|
|||
self.config.Trakt.sync_list(self.sync_to_trakt_list, current_ids)
|
||||
|
||||
def delete(self):
|
||||
if self.playlist:
|
||||
output = f"Deleting {self.Type} {self.obj.title}"
|
||||
output += f"\n{self.Type} {'deleted' if self.obj else 'not found'} on {self.library.account.username}"
|
||||
elif self.obj:
|
||||
output = f"{self.Type} {self.obj.title} deleted"
|
||||
else:
|
||||
output = ""
|
||||
if self.obj:
|
||||
self.library.query(self.obj.delete)
|
||||
output = f"{self.Type} {self.obj.title} deleted"
|
||||
if self.playlist:
|
||||
if self.valid_users:
|
||||
|
||||
if self.playlist and self.valid_users:
|
||||
for user in self.valid_users:
|
||||
try:
|
||||
self.library.delete_user_playlist(self.obj.title, user)
|
||||
output += f"\nPlaylist {self.obj.title} deleted on User {user}"
|
||||
output += f"\nPlaylist deleted on User {user}"
|
||||
except NotFound:
|
||||
output += f"\nPlaylist {self.obj.title} not found on User {user}"
|
||||
output += f"\nPlaylist not found on User {user}"
|
||||
return output
|
||||
|
||||
def sync_playlist(self):
|
||||
|
|
|
@ -417,6 +417,7 @@ class Plex(Library):
|
|||
self.type = self.Plex.type.capitalize()
|
||||
self._users = []
|
||||
self._all_items = []
|
||||
self._account = None
|
||||
self.agent = self.Plex.agent
|
||||
self.is_movie = self.type == "Movie"
|
||||
self.is_show = self.type == "Show"
|
||||
|
@ -615,7 +616,7 @@ class Plex(Library):
|
|||
def users(self):
|
||||
if not self._users:
|
||||
users = []
|
||||
for user in self.PlexServer.myPlexAccount().users():
|
||||
for user in self.account.users():
|
||||
if self.PlexServer.machineIdentifier in [s.machineIdentifier for s in user.servers]:
|
||||
users.append(user.title)
|
||||
self._users = users
|
||||
|
@ -624,6 +625,12 @@ class Plex(Library):
|
|||
def delete_user_playlist(self, title, user):
|
||||
self.PlexServer.switchUser(user).playlist(title).delete()
|
||||
|
||||
@property
|
||||
def account(self):
|
||||
if self._account is None:
|
||||
self._account = self.PlexServer.myPlexAccount()
|
||||
return self._account
|
||||
|
||||
def playlist_report(self):
|
||||
playlists = {}
|
||||
def scan_user(server, username):
|
||||
|
@ -634,7 +641,7 @@ class Plex(Library):
|
|||
playlists[playlist.title].append(username)
|
||||
except requests.exceptions.ConnectionError:
|
||||
pass
|
||||
scan_user(self.PlexServer, self.PlexServer.myPlexAccount().title)
|
||||
scan_user(self.PlexServer, self.account.title)
|
||||
for user in self.users:
|
||||
scan_user(self.PlexServer.switchUser(user), user)
|
||||
return playlists
|
||||
|
|
|
@ -21,6 +21,9 @@ class TimeoutExpired(Exception):
|
|||
class Failed(Exception):
|
||||
pass
|
||||
|
||||
class Deleted(Exception):
|
||||
pass
|
||||
|
||||
class NotScheduled(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ from modules import util
|
|||
util.logger = logger
|
||||
from modules.builder import CollectionBuilder
|
||||
from modules.config import ConfigFile
|
||||
from modules.util import Failed, NotScheduled
|
||||
from modules.util import Failed, NotScheduled, Deleted
|
||||
|
||||
def my_except_hook(exctype, value, tb):
|
||||
for _line in traceback.format_exception(etype=exctype, value=value, tb=tb):
|
||||
|
@ -816,6 +816,8 @@ def run_playlists(config):
|
|||
|
||||
builder.send_notifications(playlist=True)
|
||||
|
||||
except Deleted as e:
|
||||
logger.info(e)
|
||||
except NotScheduled as e:
|
||||
logger.info(e)
|
||||
if str(e).endswith("and was deleted"):
|
||||
|
|
Loading…
Reference in a new issue