From 37727a69ed06626875390f2481b65741d0f883ed Mon Sep 17 00:00:00 2001 From: Ty Hahn Date: Wed, 7 Aug 2019 04:53:31 +0900 Subject: [PATCH 1/2] Add rate function to video --- README.rst | 6 ++++++ plexapi/video.py | 7 +++++++ tests/test_actions.py | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/README.rst b/README.rst index 43dea560..d8a9a0d1 100644 --- a/README.rst +++ b/README.rst @@ -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 -------------------------- diff --git a/plexapi/video.py b/plexapi/video.py index 837331a0..a6754e53 100644 --- a/plexapi/video.py +++ b/plexapi/video.py @@ -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 diff --git a/tests/test_actions.py b/tests/test_actions.py index 614bbbd4..3621a903 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -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) From 1d663b920958655e4682f8959ce6f7826fec2a9f Mon Sep 17 00:00:00 2001 From: Ty Hahn Date: Wed, 7 Aug 2019 05:55:03 +0900 Subject: [PATCH 2/2] Lint --- plexapi/library.py | 2 +- plexapi/server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plexapi/library.py b/plexapi/library.py index c3b00382..239d267c 100644 --- a/plexapi/library.py +++ b/plexapi/library.py @@ -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') diff --git a/plexapi/server.py b/plexapi/server.py index ff4d1bbb..741249ce 100644 --- a/plexapi/server.py +++ b/plexapi/server.py @@ -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