Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markPlayed and markUnplayed Error for medias from Plex Discover #1067

Closed
simonc56 opened this issue Dec 18, 2022 · 4 comments · Fixed by #1090
Closed

markPlayed and markUnplayed Error for medias from Plex Discover #1067

simonc56 opened this issue Dec 18, 2022 · 4 comments · Fixed by #1090

Comments

@simonc56
Copy link
Contributor

Describe the Bug

Plex Discover allows to get Movies and Shows that user don't have in PMS library.
Problem : the markPlayed() and markUnplayed() functions do not work for those medias found with discover.provider.plex.tv it raises a plexapi.exceptions.NotFound.

Movies and Shows (found from Plex Discover) watched status can be switched with Plex Client, we shoud be able to do it through Plex API too.

Code Snippets

>>> myMovie
<Movie:nan:Cairo-Conspiracy>
>>> myMovie.markPlayed()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\plexapi\mixins.py", line 274, in markPlayed
    self._server.query(key, params=params)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\plexapi\server.py", line 705, in query
    raise NotFound(message)
plexapi.exceptions.NotFound: (404) not_found; https://metadata.provider.plex.tv/:/scrobble?key=nan&identifier=com.plexapp.plugins.library <Error error="Not Found" message="Not Found" statusCode="404"/>

Expected Behavior

No error raised.
Just like items from user's PMS library.

Additional Context

Requests to switch watched state of items from Plex Discover are :

https://discover.provider.plex.tv/actions/scrobble
https://discover.provider.plex.tv/actions/unscrobble

with data:

key=(ratingKey)
X-Plex-Token=(accessToken)
...

And we can check viewCount and lastViewdAt with request :
https://metadata.provider.plex.tv/library/metadata/(ratingKey)/userState

I think this uses the same Plex cloud database (linked to user account) to sync PMS watched state and ratings.

Operating System and Version

Windows 10

Plex Media Server Version

1.29.2.6364

Python Version

3.7

PlexAPI Version

4.13.1

@RileyXX
Copy link

RileyXX commented Jan 10, 2023

Using Plex Discover to mark items as played/unplayed is a clever way to do this. +1 for this issue

@glensc
Copy link
Contributor

glensc commented Jan 11, 2023

Started something:

If you could test, would be awesome

@glensc
Copy link
Contributor

glensc commented Jan 11, 2023

@twolaw I think you should just use these methods in your project directly:

  • def isPlayed(self, item):
    """ Returns True if this item is played. """
    userState = self.userState(item)
    return bool(userState.viewCount > 0) if userState.viewCount else False
    def markPlayed(self, item):
    """ Mark the Plex object as played. """
    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. """
    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

later if #1090 gets merged can use the PlexApi methods.

@RileyXX
Copy link

RileyXX commented May 24, 2023

Good work guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants