FORUMS
Remove All Ads from XDA
Honor 7x
Win an Honor 7X!

Plex / Python / Chromecast

10 posts
Thanks Meter: 4
 
By linc-thra, Junior Member on 16th December 2016, 11:51 PM
Post Reply Email Thread
So, I'm trying to cast plex content to my chromecast using a python script on the server. Using PlexAPI I can connect to the server and navigate my content just fine. Using pychromecast, I can connect python to my chromecast. Using the Plex Media Controller, I can even use .play() to bring the basic plex background up on the chromecast. What I -can't- seem to do is tell the plex on the chromecast WHAT to play from python... or to even actually start playing any media that isn't already playing there; it just sits there. Anyone have any insights?
 
 
18th December 2016, 01:50 AM |#2  
OP Junior Member
Thanks Meter: 4
 
More
Alright, well here's where I am: As near as I can tell, there's no way to tell the Plex Chromecast Receiver to play a title/file/anything, even once it's up. I can, of course, use PlexAPI to do things like poll for the oldest unwatched episode of something. Therefore, I'm currently tinkering with getting the episode file with PlexAPI and then sending to the chromecast with stream2chromecast. This lets me transcode, at least, to make the right video play (with audio even). Unfortunately, when transcoding, the "pause"/"continue" functions of stream2chromecast don't work. Not sure what's up with that, but it's on their end.
EvenGhost was being a pita and kept crashing on me for some reason, so I gave up on it and wrote a Tornado server into the python script. Not ideal, nor do I really want a webserver up and running at home, but it is what it is for the moment.
So the current flow goes "Google Home -> IFTTT -> Maker -> Tornado Server (python code inside) -> Chromecast.
Using this, I can now say "Okay Google, Chromecast the latest episode of MayGyver"... and in a few seconds the oldest unwatched episode from my Plex server will start to play on my TV. (I can also say, "Okay Google, chromecast stop" and it will stop.)
Sadly, because I'm sidestepping Plex for the actual playing, it doesn't show up under "now playing". Nor does it mark the episode as watched if you finish it.
20th December 2016, 12:13 AM |#3  
OP Junior Member
Thanks Meter: 4
 
More
Alright, well. Today's progress update. Rather than continue the external tracking path, I've dropped back to attempting to make it play to the Plex app on the Chromecast. I originally thought this impossible, but I did manage to make some progress.
I still cannot make a video play via this method, but I -am- able to bring up the "Details" page of any given movie or episode or whatever onto the Chromecast. I accomplished this by digging into the pychromecast Controllers and its notes about custom namespaces. I did the whole "net-internals/#capture" thing the github mentions to explore the namespace. Digging through, that gave me what commands are being sent to the Chromecast when I cast from my browser. I translated the two commands there (SHOWDETAILS and LOAD) into the Plex Controller. I was somewhat surprised when ShowDetails actually worked.... but then shatteringly disappointed when LOAD did not.
I feel like I'm so close on this now, but still missing a piece of the puzzle.
The Following User Says Thank You to linc-thra For This Useful Post: [ View ] Gift linc-thra Ad-Free
30th December 2016, 10:14 AM |#4  
Junior Member
Thanks Meter: 2
 
More
Nice work. You've converted me - I was just using the standard media controller to access the respective Plex url. The tips above helped guide me in the right direction. So thanks - and keep posting your progress. I'll see what I can figure out as well. I assume you already sorted out the transient access tokens that look to be required?
30th December 2016, 03:08 PM |#5  
Junior Member
Thanks Meter: 2
 
More
Ok I got the play working via Python.
I use this API - github.com/mjs7231/python-plexapi
The key things I had to do:
1. Grab a transient token for the request
Code:
server.query('/security/token?type=delegation&scope=all').attrib('token')
2. And I created a playQueue id for the request
Code:
server.createPlayQueue(video).playQueueID
3. The LOAD command must be run in the namespace:
Code:
urn:x-cast:com.google.cast.media
not
Code:
urn:x-cast:plex
I just switched namespaces in my PlexController (as I built a custom LOAD message) to prove it would work
The Following 2 Users Say Thank You to mcneishh For This Useful Post: [ View ] Gift mcneishh Ad-Free
30th December 2016, 08:17 PM |#6  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by mcneishh

Ok I got the play working via Python.
I use this API - github.com/mjs7231/python-plexapi
The key things I had to do:
1. Grab a transient token for the request

Code:
server.query('/security/token?type=delegation&scope=all').attrib('token')
2. And I created a playQueue id for the request
Code:
server.createPlayQueue(video).playQueueID
3. The LOAD command must be run in the namespace:
Code:
urn:x-cast:com.google.cast.media
not
Code:
urn:x-cast:plex
I just switched namespaces in my PlexController (as I built a custom LOAD message) to prove it would work


Can you provide some more details on how you did the LOAD command part? That's the part I'm having the most trouble with.
30th December 2016, 08:18 PM |#7  
OP Junior Member
Thanks Meter: 4
 
More
Ah, I had NOT indeed worked out the transient token bit. I felt like maybe I needed to fetch one, but hadn't quite worked out how. Are you sending a SETSTREAM and a LOAD or just a LOAD to actually get things playing? If a SETSTREAM, is that going to the plex namespace or the media namespace?
31st December 2016, 12:30 AM |#8  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by linc-thra

Ah, I had NOT indeed worked out the transient token bit. I felt like maybe I needed to fetch one, but hadn't quite worked out how. Are you sending a SETSTREAM and a LOAD or just a LOAD to actually get things playing? If a SETSTREAM, is that going to the plex namespace or the media namespace?

How did you go about sending the commands to the chromecast? I've spent most of the day trying to figure out pychromecast, but I'm not having much luck. I just cannot figure out how to expand the namespace to add a new plex module. I feel like if I could get anything to send it would be a huge leap in the right direction...
31st December 2016, 12:38 AM |#9  
OP Junior Member
Thanks Meter: 4
 
More
Quote:
Originally Posted by MechaTech84

How did you go about sending the commands to the chromecast? I've spent most of the day trying to figure out pychromecast, but I'm not having much luck. I just cannot figure out how to expand the namespace to add a new plex module. I feel like if I could get anything to send it would be a huge leap in the right direction...

I'm headed out to dinner and won't be back for a while, BUT, it requires editing the plex.py file in the controller folder of pychromecast. I JUST got it to start playing and the like myself thanks to mcneishh's hints. I'm attaching a basic functional PlexApiController:

http://pastebin.com/qeLYZpW4

I'll try to improve it later.
An example of how to use this:

Code:
import pychromecast.controllers.plexapi as px
import pychromecast
from plexapi.myplex import MyPlexAccount
account = MyPlexAccount.signin('<USERNAME>', '<PASSWORD')
plex = account.resource('<SERVER_NAME>').connect()
pxr = px.PlexController()
cast = pychromecast.Chromecast("<CHROMECASTIP")
cast.register_handler(pxr)
pxr.namespace = 'urn:x-cast:com.google.cast.sse'
white = plex.library.section("TV Shows").get("White Collar")
epi = white.seasons()[0].episodes()[0]
pxr.play_media(epi,plex)
The Following User Says Thank You to linc-thra For This Useful Post: [ View ] Gift linc-thra Ad-Free
31st December 2016, 01:12 AM |#10  
OP Junior Member
Thanks Meter: 4
 
More
My bad, that first code line should be
Code:
import pychromecast.controllers.plex as px
if you edit the existing plex.py file, I think. I had made my own at plexapi.py so as not to lose the original.
The Following User Says Thank You to linc-thra For This Useful Post: [ View ] Gift linc-thra Ad-Free
1st January 2017, 06:54 PM |#11  
Senior Member
Thanks Meter: 375
 
More
Is there a reason why you are trying to do this and not use the Plex App? Is it just a coding experiment or is there some reason why you want to bypass the Plex app?
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes