[3] fix deleting playlists

pull/896/head
meisnate12 3 years ago
parent 3e8cb33a83
commit e64c56f4f2

@ -1 +1 @@
1.17.0-develop2 1.17.0-develop3

@ -1,7 +1,7 @@
import os, re, time import os, re, time
from datetime import datetime 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 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.audio import Artist, Album, Track
from plexapi.exceptions import BadRequest, NotFound from plexapi.exceptions import BadRequest, NotFound
from plexapi.video import Movie, Show, Season, Episode from plexapi.video import Movie, Show, Season, Episode
@ -293,7 +293,7 @@ class CollectionBuilder:
logger.debug(f"Value: {data[methods['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): if util.parse(self.Type, "delete_playlist", self.data, datatype="bool", methods=methods, default=False):
self.obj = self.library.get_playlist(self.name) self.obj = self.library.get_playlist(self.name)
logger.info(self.delete()) raise Deleted(self.delete())
else: else:
self.libraries.append(self.library) self.libraries.append(self.library)
@ -2576,18 +2576,23 @@ class CollectionBuilder:
self.config.Trakt.sync_list(self.sync_to_trakt_list, current_ids) self.config.Trakt.sync_list(self.sync_to_trakt_list, current_ids)
def delete(self): def delete(self):
output = "" 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: if self.obj:
self.library.query(self.obj.delete) self.library.query(self.obj.delete)
output = f"{self.Type} {self.obj.title} deleted"
if self.playlist: if self.playlist and self.valid_users:
if self.valid_users: for user in self.valid_users:
for user in self.valid_users: try:
try: self.library.delete_user_playlist(self.obj.title, user)
self.library.delete_user_playlist(self.obj.title, user) output += f"\nPlaylist deleted on User {user}"
output += f"\nPlaylist {self.obj.title} deleted on User {user}" except NotFound:
except NotFound: output += f"\nPlaylist not found on User {user}"
output += f"\nPlaylist {self.obj.title} not found on User {user}"
return output return output
def sync_playlist(self): def sync_playlist(self):

@ -417,6 +417,7 @@ class Plex(Library):
self.type = self.Plex.type.capitalize() self.type = self.Plex.type.capitalize()
self._users = [] self._users = []
self._all_items = [] self._all_items = []
self._account = None
self.agent = self.Plex.agent self.agent = self.Plex.agent
self.is_movie = self.type == "Movie" self.is_movie = self.type == "Movie"
self.is_show = self.type == "Show" self.is_show = self.type == "Show"
@ -615,7 +616,7 @@ class Plex(Library):
def users(self): def users(self):
if not self._users: if not self._users:
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]: if self.PlexServer.machineIdentifier in [s.machineIdentifier for s in user.servers]:
users.append(user.title) users.append(user.title)
self._users = users self._users = users
@ -624,6 +625,12 @@ class Plex(Library):
def delete_user_playlist(self, title, user): def delete_user_playlist(self, title, user):
self.PlexServer.switchUser(user).playlist(title).delete() 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): def playlist_report(self):
playlists = {} playlists = {}
def scan_user(server, username): def scan_user(server, username):
@ -634,7 +641,7 @@ class Plex(Library):
playlists[playlist.title].append(username) playlists[playlist.title].append(username)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
pass pass
scan_user(self.PlexServer, self.PlexServer.myPlexAccount().title) scan_user(self.PlexServer, self.account.title)
for user in self.users: for user in self.users:
scan_user(self.PlexServer.switchUser(user), user) scan_user(self.PlexServer.switchUser(user), user)
return playlists return playlists

@ -21,6 +21,9 @@ class TimeoutExpired(Exception):
class Failed(Exception): class Failed(Exception):
pass pass
class Deleted(Exception):
pass
class NotScheduled(Exception): class NotScheduled(Exception):
pass pass

@ -112,7 +112,7 @@ from modules import util
util.logger = logger util.logger = logger
from modules.builder import CollectionBuilder from modules.builder import CollectionBuilder
from modules.config import ConfigFile 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): def my_except_hook(exctype, value, tb):
for _line in traceback.format_exception(etype=exctype, value=value, tb=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) builder.send_notifications(playlist=True)
except Deleted as e:
logger.info(e)
except NotScheduled as e: except NotScheduled as e:
logger.info(e) logger.info(e)
if str(e).endswith("and was deleted"): if str(e).endswith("and was deleted"):

Loading…
Cancel
Save