Update updatePlexList to use plexApi
it no longer uses requests_cache directly
MODIFY
plex_trakt_sync/commands/sync.py
plex_trakt_sync/commands/sync.py
@@ -89,7 +89,7 @@ def sync_all(walker: Walker, trakt: TraktApi, plex: PlexApi):
listutil.addPlexItemToLists(episode)
with measure_time("Updated plex watchlist"):
- listutil.updatePlexLists(server)
+ listutil.updatePlexLists(plex)
trakt.flush()

MODIFY
plex_trakt_sync/trakt_list_util.py
plex_trakt_sync/trakt_list_util.py
+from itertools import count
+
from trakt.users import UserList
from trakt.errors import NotFoundException, OAuthException
from trakt.movies import Movie
from trakt.tv import TVEpisode
from plexapi.video import Episode
-from plex_trakt_sync.requests_cache import requests_cache
+
+from plex_trakt_sync.plex_api import PlexApi
from plex_trakt_sync.logging import logger
-from plexapi.exceptions import BadRequest, NotFound
-from itertools import count
class TraktList():
@@ -31,16 +32,11 @@ def addPlexItem(self, trakt_item, plex_item):
else:
logger.info('Movie [{} ({})]: added to list {}'.format(plex_item.title, plex_item.year, self.name))
- def updatePlexList(self, plex):
- with requests_cache.disabled():
- try:
- plex.playlist(self.name).delete()
- except (NotFound, BadRequest):
- logger.debug("Playlist %s not found, so it could not be deleted. Actual playlists: %s" % (self.name, plex.playlists()))
- pass
+ def updatePlexList(self, plex: PlexApi):
+ plex.delete_playlist(self.name)
+
if len(self.plex_items) > 0:
- _, plex_items_sorted = zip(*sorted(dict(reversed(self.plex_items)).items()))
- plex.createPlaylist(self.name, items=plex_items_sorted)
+ plex.create_playlist(self.name, self.plex_items)
class TraktListUtil():
@@ -62,6 +58,6 @@ def addPlexItemToLists(self, m):
for l in self.lists:
l.addPlexItem(m.trakt, m.plex.item)
- def updatePlexLists(self, plex):
+ def updatePlexLists(self, plex: PlexApi):
for l in self.lists:
l.updatePlexList(plex)

Update updatePlexList to use plexApi

it no longer uses requests_cache directly