Add create_playlist and delete_playlist methods
import datetime
from typing import Union
+from plexapi.exceptions import BadRequest, NotFound
from plexapi.library import MovieSection, ShowSection, LibrarySection
from plexapi.server import PlexServer
from plex_trakt_sync.config import CONFIG
from trakt.utils import timestamp
+from plex_trakt_sync.logging import logger
+
class PlexGuid:
def __init__(self, guid: str, type: str, pm: PlexLibraryItem):
@@ -294,6 +297,18 @@ def library_sections(self):
def rate(self, m, rating):
m.rate(rating)
+ @nocache
+ def create_playlist(self, name: str, items):
+ _, plex_items_sorted = zip(*sorted(dict(reversed(items)).items()))
+ self.plex.createPlaylist(name, items=plex_items_sorted)
+
+ @nocache
+ def delete_playlist(self, name: str):
+ try:
+ self.plex.playlist(name).delete()
+ except (NotFound, BadRequest):
+ logger.debug(f"Playlist '{name}' not found, so it could not be deleted")
+
@nocache
def mark_watched(self, m):
m.markWatched()
