Add support Discover isPlayed/markPlayed/markUnplayed (#1090)

* Add isPlayed, markPlayed, markUnplayed to MyPlexAccount

* Add documentation for item

* Clarify that the methods change on Discover
This commit is contained in:
Elan Ruusamäe 2023-05-24 21:37:13 +03:00 committed by GitHub
parent 7ae5ec7da0
commit 981f1624ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -936,6 +936,48 @@ class MyPlexAccount(PlexObject):
data = self.query(f"{self.METADATA}/library/metadata/{ratingKey}/userState")
return self.findItem(data, cls=UserState)
def isPlayed(self, item):
""" Return True if the item is played on Discover.
Parameters:
item (:class:`~plexapi.video.Movie`,
:class:`~plexapi.video.Show`, :class:`~plexapi.video.Season` or
:class:`~plexapi.video.Episode`): Object from searchDiscover().
Can be also result from Plex Movie or Plex TV Series agent.
"""
userState = self.userState(item)
return bool(userState.viewCount > 0) if userState.viewCount else False
def markPlayed(self, item):
""" Mark the Plex object as played on Discover.
Parameters:
item (:class:`~plexapi.video.Movie`,
:class:`~plexapi.video.Show`, :class:`~plexapi.video.Season` or
:class:`~plexapi.video.Episode`): Object from searchDiscover().
Can be also result from Plex Movie or Plex TV Series agent.
"""
key = f'{self.METADATA}/actions/scrobble'
ratingKey = item.guid.rsplit('/', 1)[-1]
params = {'key': ratingKey, 'identifier': 'com.plexapp.plugins.library'}
self.query(key, params=params)
return self
def markUnplayed(self, item):
""" Mark the Plex object as unplayed on Discover.
Parameters:
item (:class:`~plexapi.video.Movie`,
:class:`~plexapi.video.Show`, :class:`~plexapi.video.Season` or
:class:`~plexapi.video.Episode`): Object from searchDiscover().
Can be also result from Plex Movie or Plex TV Series agent.
"""
key = f'{self.METADATA}/actions/unscrobble'
ratingKey = item.guid.rsplit('/', 1)[-1]
params = {'key': ratingKey, 'identifier': 'com.plexapp.plugins.library'}
self.query(key, params=params)
return self
def searchDiscover(self, query, limit=30, libtype=None):
""" Search for movies and TV shows in Discover.
Returns a list of :class:`~plexapi.video.Movie` and :class:`~plexapi.video.Show` objects.