pkkid / python-plexapi

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

Support Live TV and DVR #182

Open fdarveau opened 7 years ago

fdarveau commented 7 years ago

Live TV and DVR is now out of beta and there is an endpoint available : /livetv/.

I haven't explored it much myself yet, but it would be nice to add to this wrapper.

Hellowlol commented 7 years ago

Don't you need a 📺 card to use this?

fdarveau commented 7 years ago

You need either a supported tuner, either a card to put in your PC or a network connected one such as the HDHomerun.

There is an API endpoint to get the available tuners (/livetv/dvrs).

Hellowlol commented 7 years ago

Unless pkkid has a tuner this will not be added before we get a pr. I dont have the equipment.

pkkid commented 7 years ago

I don't have the equipment either.

blacktwin commented 5 years ago

I have this enabled. Are there specific things we'd want to see or be able to do? Looking for focus points.

Hellowlol commented 5 years ago

I don’t have a tv card so I have no idea

fdarveau commented 5 years ago

I'm not sure what kind of things you want this project to have or what the Plex API offers, but here are some suggestions :

blacktwin commented 5 years ago

Endpoints for anyone else

LIVETV List DVRs GET http://127.0.0.1:32400/livetv/dvrs

LiveTV Sessions GET http://127.0.0.1:32400/livetv/sessions

Find your cloud key GET http://127.0.0.1:32400/tv.plex.providers.epg.cloud

Mine cloud key is 51 as you can see below.

opening library GET http://127.0.0.1:32400/tv.plex.providers.epg.cloud:51/hubs/discover?excludeFields=summary&count=17&includeEmpty=1&includeFeaturedTags=1&includeTypeFirst=1&includeStations=1&includeExternalMedia=1&includeExternalMetadata=1&excludePlaylists=1&onlyTransient=1

http://127.0.0.1:32400/tv.plex.providers.epg.cloud:51/hubs/discover

playing a channel POST http://127.0.0.1:32400/livetv/dvrs/51/channels/809/tune

Guide page GET http://127.0.0.1:32400/tv.plex.providers.epg.cloud:51/grid?type=1%2C4&sort=beginsAt&endsAt%3E=1568403000&beginsAt%3C=1568410200

http://127.0.0.1:32400/tv.plex.providers.epg.cloud:51/grid?type=1

DVR Schedule GET http://127.0.0.1:32400/media/subscriptions/scheduled

DVR'd items http://127.0.0.1:32400/media/subscriptions

Set recording POST (not sure what is the minimum requirement for setting a recording) http://127.0.0.1:32400/media/subscriptions?prefs%5BminVideoQuality%5D=0&prefs%5BreplaceLowerQuality%5D=false&prefs%5BrecordPartials%5D=true&prefs%5BstartOffsetMinutes%5D=0&prefs%5BendOffsetMinutes%5D=0&prefs%5BlineupChannel%5D=&prefs%5BstartTimeslot%5D=-1&prefs%5BcomskipEnabled%5D=-1&prefs%5BoneShot%5D=true&prefs%5BremoteMedia%5D=false&targetLibrarySectionID=3&targetSectionLocationID=&includeGrabs=1&hints[grandparentGuid]=plex%3A%2F%2Fshow%2F5cffa16679f52f001d7876ca&hints[grandparentThumb]=http%3A%2F%2Fcps-static%2Erovicorp%2Ecom%2F2%2FOpen%2FNBC%2520Universal%2520Distribution%2FMaury%2FMaury_HOST%2Ejpg&hints[grandparentTitle]=Maury&hints[grandparentYear]=1998&hints[guid]=plex%3A%2F%2Fepisode%2F5d70e0459b8692001faa5b5c&hints[index]=11&hints[originallyAvailableAt]=2017-10-02&hints[parentGuid]=plex%3A%2F%2Fseason%2F5cffa16679f52f001d7876ca%2F20&hints[parentIndex]=20&hints[parentTitle]=Season%2020&hints[ratingKey]=plex%253A%252F%252Fepisode%252F5d70e0459b8692001faa5b5c&hints[title]=DNA%20Will%20Prove%20I%20Have%202%20Babies%20With%20Your%20Husband!&hints[type]=4&hints[year]=2017&params[airingChannels]=002%253D002%252520WDCW%252520(CW)%2526803%253D803%252520WDCWH%252520(CW)&params[airingTimes]=1260&params[libraryType]=2&params[mediaProviderID]=53&type=4

Remove recording DELETE http://127.0.0.1:32400/media/subscriptions/285

Selecting a show from Guide http://127.0.0.1:32400/tv.plex.providers.epg.cloud:51/metadata/plex%3A%2F%2Fshow%2F{MACHINE_ID}?Accept-Language=en&includeConcerts=1&includeExtras=1&includeOnDeck=1&includePopularLeaves=1&includePreferences=1&includeChapters=1&includeStations=1&includeExternalMedia=1&asyncAugmentMetadata=1&asyncCheckFiles=1&asyncRefreshAnalysis=1&asyncRefreshLocalMediaAgent=1

http://127.0.0.1:32400/tv.plex.providers.epg.cloud:51/metadata/plex%3A%2F%2Fshow%2F{MACHINE_ID}

Another interesting find Hubs GET http://127.0.0.1:32400/hubs

ReenigneArcher commented 3 years ago

@blacktwin The cloud key method returns no key for me. I think if you are using Plex's guide then it gives you a cloud key. If you are using an xml then you use the Dvr Key, which you can get from your first example.

Refresh Guide Data (POST request) http://127.0.0.1:32400/livetv/dvrs/<dvr_key>/reloadGuide

This javascript also has a method to update the channels. I don't understand javascript enough to interpret the PUT request being used. Would be nice to automatically enable and map all channels (in the event new channels are added). https://github.com/vexorian/dizquetv/blob/f428dbecf0c4fd51f9fba1a91fa98eaaae7bbdb8/src/plex.js#L176

adriel commented 1 year ago

The DVR'd items, is also called "Recording Priority", incase someone else is looking to get that data.

http://127.0.0.1:32400/media/subscriptions

It's pretty easy to interact direct with Plex, here's what I did:

import requests

# Plex config
base_url = 'http://127.0.0.1:32400'
token = 'your_plex_token'

# Set the headers for the API request
headers = {
    "X-Plex-Token": token
}

# Make a GET request to the Recording Priority endpoint
response = requests.get(base_url + "/media/subscriptions", headers=headers)

# Print the response from the API
print(response.content)