pkkid / python-plexapi

Python bindings for the Plex API.
BSD 3-Clause "New" or "Revised" License
1.13k stars 196 forks source link

List watched episodes by any Plex Home user #65

Closed philipsd6 closed 4 years ago

philipsd6 commented 8 years ago

I have limited disk space, so I've been running a script that gathers all watched episodes and deletes them, then refreshes the plex media server. Works great. But then I set up Plex Home for other family members, and I still need to delete the episodes they've watched. But even though I'm the admin user, I cannot see the state of the shows they've watched. I even tried using their login/password to authenticate with my script, but then the script doesn't work at all, because they aren't the administrator.

Is there any way the API can be used to see the watched state of episodes for other Plex Home child accounts?

pkkid commented 7 years ago

Hey philipsd6 -- Sorry I haven't looked at this yet; I have been meaning to. Just wanted to update you that it's still on my mind and hope to get back to plexapi work shortly.

Unless I'm mistaken, I don't think there is a way to see the watched status of another user without logging in as that user (Home or Shared). But I never looked deeply into it yet. I'll google a bit to see if other people found a solution to this.

philipsd6 commented 7 years ago

Maybe I've got this wrong, but I can't seem to log into my plex instance using another user account in my Home:

In [10]: account = MyPlexAccount.signin('joe@example.com', 'joessekrit')
In [11]: account.resources()
Out[11]: [<MyPlexResource:myplexsvr>, <MyPlexResource:My FireTV>]
In [12]: myplexsvr = account.resource('myplexsvr')
In [13]: myplexsvr.connections
Out[13]: [<ResourceConnection:https://IP-ADDRESS.UUID.plex.direct:32400>]
In [14]: plex = myplexsvr.connect()
---------------------------------------------------------------------------
NotFound                                  Traceback (most recent call last)
<ipython-input-26-f888b543793a> in <module>()
----> 1 plex = myplexsvr.connect()

/usr/local/lib/python2.7/site-packages/plexapi/myplex.pyc in connect(self, ssl)
    155         results = list(filter(None, [r[2] for r in results if r]))
    156         if not results:
--> 157             raise NotFound('Unable to connect to resource: %s' % self.name)
    158         log.info('Connecting to server: %s?X-Plex-Token=%s', results[0].baseurl, results[0].token)
    159         return results[0]

NotFound: Unable to connect to resource: myplexsvr

If I use my primary account instead of the Home user account, the above code works fine.

billbo99 commented 6 years ago

Any progress on this ? I would like to run some logic myself, archive shows that have been watch by both myself and wife. But as above I can't see anything obvious in the API to list episode statuses by User.

Hellowlol commented 6 years ago

@billbo99 Cant you use PlexServer().history()? btw you should look into plexpy for things like this.

Technifocal commented 6 years ago

@Hellowlol Issue with PlexPy is it only detects history, not watch status, meaning if I watch a show via some other means and mark it as watched on Plex, PlexPy doesn't seem to be able to pick this up, unless I'm missing something.

pkkid commented 6 years ago

I think you need access to the backend database directly to see the watched status of other users. At least the Plex Web Client does not show you that information. If that's the case it would be something we are not setting out to support with this library.

Hellowlol commented 6 years ago

It cant pick it up if you have seen vis other means (VLC, kodi) but can use use plexapi for your self then plexpy for other users.

Hellowlol commented 6 years ago

It cant pick it up if you have seen vis other means (VLC, kodi) but can use use plexapi for your self then plexpy for other users.

blacktwin commented 5 years ago

PlexPy/Tautulli might be the better option for handling this but you can access the watched statuses of other users via PlexAPI.

plex = PlexServer(PLEX_URL, PLEX_TOKEN)
account = plex.myPlexAccount()
user_acct = account.user('USERNAME')
user_plex = PlexServer(PLEX_URL, user_acct.get_token(plex.machineIdentifier))

Because the user_plex is a server object you can do most of the same things you would be able to in the admin's server object (create, update, or delete playlists, mark watched or unwatched, etc.)

movies = user_plex.library.section('Movies')
for video in movies.search(unwatched=True):
    print(video.title)
blacktwin commented 4 years ago

@philipsd6 Are we OK to close this with the solution provided above?

philipsd6 commented 4 years ago

Sure, noone else uses my Plex anymore anyway!