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

Add deviceID to Playable for history entries #704

Merged
merged 2 commits into from
Mar 22, 2021

Conversation

glensc
Copy link
Contributor

@glensc glensc commented Mar 21, 2021

This is needed to identify devices from play history:

    history = movie.history()
    for h in history:
        print("- Watched: %s (%s) -> %s,%s" % (h.viewedAt, h.lastViewedAt, h.accountID, h.deviceID))

@glensc
Copy link
Contributor Author

glensc commented Mar 21, 2021

Also need some help, how to find Device based on that Id?

There's plex.systemDevices(), but it returns all devices, not the specific one I'm interested of.

Also, the offset is off by one when accessing as index, so need to use lookup;

I've come up with this:

    devices = plex.systemDevices()
    history = movie.history()
    for h in history:
        # device = devices[h.deviceID] <- devices is not indexed by deviceId
        device = next(x for x in devices if x.id == h.deviceID)

plexapi/base.py Show resolved Hide resolved
@JonnyWong16
Copy link
Collaborator

JonnyWong16 commented Mar 21, 2021

Using next() will work.

I added convenience methods to retrieve the account or device by ID in #703. The methods just use next() the same way.

@glensc
Copy link
Contributor Author

glensc commented Mar 21, 2021

Using next() will work.

I added convenience methods to retrieve the account or device by ID in #703. The methods just use next() the same way.

Maybe (also) make the devices indeed by deviceId?

@JonnyWong16
Copy link
Collaborator

JonnyWong16 commented Mar 21, 2021

Maybe (also) make the devices indeed by deviceId?

I don't know what you mean.

Oh, you mean the list index. No, the order comes from Plex. They start their IDs from 1. It would also fail if a device is ever deleted (I don't know how) causing IDs be skipped.

@jjlawren jjlawren merged commit a3d4378 into pkkid:master Mar 22, 2021
@glensc glensc deleted the add-deviceID branch March 22, 2021 20:36
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 this pull request may close these issues.

3 participants