Skip to content

Commit cdda56b

Browse files
authored
Merge pull request #372 from yosnoop/rate
Add rate function to video
2 parents bd033a9 + 1d663b9 commit cdda56b

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ Usage Examples
131131
print(playlist.title)
132132
133133
134+
.. code-block:: python
135+
136+
# Example 10: Rate Mr. Robot four stars.
137+
plex.library.section('TV Shows').get('Mr. Robot').rate(8.0)
138+
139+
134140
Running tests over PlexAPI
135141
--------------------------
136142

plexapi/library.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ class ShowSection(LibrarySection):
713713
'guid', 'duplicate', 'label', 'show.title', 'show.year', 'show.userRating',
714714
'show.viewCount', 'show.lastViewedAt', 'show.actor', 'show.addedAt', 'episode.title',
715715
'episode.originallyAvailableAt', 'episode.resolution', 'episode.subtitleLanguage',
716-
'episode.unwatched', 'episode.addedAt','episode.userRating', 'episode.viewCount',
716+
'episode.unwatched', 'episode.addedAt', 'episode.userRating', 'episode.viewCount',
717717
'episode.lastViewedAt')
718718
ALLOWED_SORT = ('addedAt', 'lastViewedAt', 'originallyAvailableAt', 'titleSort',
719719
'rating', 'unwatched')

plexapi/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def history(self, maxresults=9999999, mindate=None):
334334
up the result listing. For example: datetime.now() - timedelta(days=7)
335335
"""
336336
results, subresults = [], '_init'
337-
args = {'sort':'viewedAt:desc'}
337+
args = {'sort': 'viewedAt:desc'}
338338
if mindate:
339339
args['viewedAt>'] = int(mindate.timestamp())
340340
args['X-Plex-Container-Start'] = 0

plexapi/video.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def markUnwatched(self):
7878
self._server.query(key)
7979
self.reload()
8080

81+
def rate(self, rate):
82+
""" Rate video. """
83+
key = '/:/rate?key=%s&identifier=com.plexapp.plugins.library&rating=%s' % (self.ratingKey, rate)
84+
85+
self._server.query(key)
86+
self.reload()
87+
8188
def _defaultSyncTitle(self):
8289
""" Returns str, default title for a new syncItem. """
8390
return self.title

tests/test_actions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ def test_refresh_section(tvshows):
1919

2020
def test_refresh_video(movie):
2121
movie.refresh()
22+
23+
24+
def test_rate_movie(movie):
25+
oldrate = movie.userRating
26+
movie.rate(10.0)
27+
assert movie.userRating == 10.0, 'User rating 10.0 after rating five stars.'
28+
movie.rate(oldrate)

0 commit comments

Comments
 (0)