Merge pull request #372 from yosnoop/rate

Add rate function to video
This commit is contained in:
Michael Shepanski 2019-08-07 12:36:33 -04:00 committed by GitHub
commit cdda56b548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 2 deletions

View file

@ -131,6 +131,12 @@ Usage Examples
print(playlist.title)
.. code-block:: python
# Example 10: Rate Mr. Robot four stars.
plex.library.section('TV Shows').get('Mr. Robot').rate(8.0)
Running tests over PlexAPI
--------------------------

View file

@ -713,7 +713,7 @@ class ShowSection(LibrarySection):
'guid', 'duplicate', 'label', 'show.title', 'show.year', 'show.userRating',
'show.viewCount', 'show.lastViewedAt', 'show.actor', 'show.addedAt', 'episode.title',
'episode.originallyAvailableAt', 'episode.resolution', 'episode.subtitleLanguage',
'episode.unwatched', 'episode.addedAt','episode.userRating', 'episode.viewCount',
'episode.unwatched', 'episode.addedAt', 'episode.userRating', 'episode.viewCount',
'episode.lastViewedAt')
ALLOWED_SORT = ('addedAt', 'lastViewedAt', 'originallyAvailableAt', 'titleSort',
'rating', 'unwatched')

View file

@ -334,7 +334,7 @@ class PlexServer(PlexObject):
up the result listing. For example: datetime.now() - timedelta(days=7)
"""
results, subresults = [], '_init'
args = {'sort':'viewedAt:desc'}
args = {'sort': 'viewedAt:desc'}
if mindate:
args['viewedAt>'] = int(mindate.timestamp())
args['X-Plex-Container-Start'] = 0

View file

@ -78,6 +78,13 @@ class Video(PlexPartialObject):
self._server.query(key)
self.reload()
def rate(self, rate):
""" Rate video. """
key = '/:/rate?key=%s&identifier=com.plexapp.plugins.library&rating=%s' % (self.ratingKey, rate)
self._server.query(key)
self.reload()
def _defaultSyncTitle(self):
""" Returns str, default title for a new syncItem. """
return self.title

View file

@ -19,3 +19,10 @@ def test_refresh_section(tvshows):
def test_refresh_video(movie):
movie.refresh()
def test_rate_movie(movie):
oldrate = movie.userRating
movie.rate(10.0)
assert movie.userRating == 10.0, 'User rating 10.0 after rating five stars.'
movie.rate(oldrate)