python-plexapi icon indicating copy to clipboard operation
python-plexapi copied to clipboard

Support Live TV and DVR

Open fdarveau opened this issue 8 years ago • 11 comments

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.

fdarveau avatar Sep 02 '17 20:09 fdarveau

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

Hellowlol avatar Sep 02 '17 21:09 Hellowlol

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).

fdarveau avatar Sep 02 '17 21:09 fdarveau

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

Hellowlol avatar Sep 02 '17 23:09 Hellowlol

I don't have the equipment either.

pkkid avatar Sep 02 '17 23:09 pkkid

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

blacktwin avatar Sep 13 '19 19:09 blacktwin

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

Hellowlol avatar Sep 13 '19 19:09 Hellowlol

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 :

  • Get schedule and being able to filter by channel and/or type (show, movie, news, sports are the categories that I can see in Plex, so I assume at least those would be possible)
  • Schedule a recording
  • Cancel a scheduled recording
  • Check the status of a recording (upcoming, in progress, completed, failed (with fail reason maybe?))
  • Get live feed (would that even be possible?)

fdarveau avatar Sep 13 '19 19:09 fdarveau

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

blacktwin avatar Sep 17 '19 13:09 blacktwin

@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

ReenigneArcher avatar Dec 31 '20 22:12 ReenigneArcher

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)

adriel avatar Jan 25 '23 23:01 adriel