pychromecast icon indicating copy to clipboard operation
pychromecast copied to clipboard

Plex Controller choose media

Open lincthra opened this issue 7 years ago • 23 comments

Is there any way to get the PlexController to choose the library item to play and start playing it? Right now it can only play/pause/stop, not start your chosen media. I have tried exploring the namespace as instructed with very little success (I can throw the details of any given library item to the chromecast and display them).

lincthra avatar Dec 22 '16 05:12 lincthra

@lincthra - I've actually got this figured out, and will be working it into a PR for the plex controller once I've sorted some other things.

d8ahazard avatar Jan 18 '18 02:01 d8ahazard

I'm currently in the process of adding plex support to my project (https://github.com/tizonia/tizonia-openmax-il), which uses pychromecast to cast audio URLs to chromecast devices, using the default media receiver. Currently, I can retrieve audio URLs from the plex server and play them locally, but when I try to load them onto a Chromecast device using the default media receiver, the playback does not start.

Plex urls from my server look like this one, which resolves to an mp3 file.

http://sam:32400/audio/:/transcode/universal/start.m3u8?X-Plex-Platform=Chrome&copyts=1&mediaIndex=0&offset=0&path=%2Flibrary%2Fmetadata%2F53523&X-Plex-Token=asdASDhAHdkaoqiasd

So I'm wondering what would be the limitation here, i.e. why is the default media app unable to consume this URL?

@d8ahazard : I suppose your PR to extend the plex controller would essentially resolve this issue?

Thanks!

tizonia avatar Feb 18 '18 12:02 tizonia

Here is the log: cast.log

tizonia avatar Feb 18 '18 13:02 tizonia

You may want to look at my Chromecast.bundle project, I've got a fully working Plex controller there already...

On Feb 18, 2018 7:17 AM, "Tizonia" [email protected] wrote:

Here is the log: cast.log https://github.com/balloob/pychromecast/files/1734743/cast.log

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/balloob/pychromecast/issues/146#issuecomment-366515544, or mute the thread https://github.com/notifications/unsubscribe-auth/ABjuNJQWiNvvI1Giy9rE7zc7XvzZplPrks5tWCMBgaJpZM4LTpHE .

d8ahazard avatar Feb 18 '18 16:02 d8ahazard

Sorry, a bit more info:

The playback URL's from the Plex Web app are not the same format that is sent to cast devices. I've got a controller in my project that details (for the most part) the required fields needed to initiate proper cast playback. You'll need to get the media key, then create a play queue and get a transient token from the playback server, then send the media key, path, transient token, playqueue ID...and a few other params.

Unfortunately, I don't have this all automated in the controller, as I have another app that fetches and sends that data already.

But, the controller should still work for other uses.

https://github.com/d8ahazard/Cast.bundle

On Sun, Feb 18, 2018 at 10:22 AM, Ben K. [email protected] wrote:

You may want to look at my Chromecast.bundle project, I've got a fully working Plex controller there already...

On Feb 18, 2018 7:17 AM, "Tizonia" [email protected] wrote:

Here is the log: cast.log https://github.com/balloob/pychromecast/files/1734743/cast.log

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/balloob/pychromecast/issues/146#issuecomment-366515544, or mute the thread https://github.com/notifications/unsubscribe-auth/ABjuNJQWiNvvI1Giy9rE7zc7XvzZplPrks5tWCMBgaJpZM4LTpHE .

d8ahazard avatar Feb 18 '18 17:02 d8ahazard

@d8ahazard . Thanks. I haven't got a chance to look at your code yet, but

URL's from the Plex Web app are not the same format that is sent to cast devices

I can't see how they are different. Would you be able to elaborate?

Here is an example, when an http request with this URL is issued, the Plex server returns the below headers and the mp3 data. I.e. the URL can be played back in tizonia, mplayer, cvlc, etc or any other media player (but not the Chromecast default media receiver).

tizonia 'http://sam:32400/audio/:/transcode/universal/start.m3u8?X-Plex-Platform=Chrome&copyts=1&mediaIndex=0&offset=0&path=%2Flibrary%2Fmetadata%2F53523&X-Plex-Token=asdasdasdasdaasdasd' 
tizonia 0.12.0. Copyright (C) 2018 Juan A. Rubio
This software is part of the Tizonia project <http://tizonia.org>

[http] [Connecting to radio station] : 'http://sam:32400/audio/:/transcode/universal/start.m3u8?X-Plex-Platform=Chrome&copyts=1&mediaIndex=0&offset=0&path=%2Flibrary%2Fmetadata%2F53523&X-Plex-Token=asdaasdasdasdasd'.
     Content-Type : audio/mpeg
     Accept-Ranges : none
     Connection : close
     X-Plex-Protocol : 1.0
     Cache-Control : no-cache
     Date : Sun, 18 Feb 2018 20:46:55 GMT
[http/mp3] [Connected] : 'http://sam:32400/audio/:/transcode/universal/start.m3u8?X-Plex-Platform=Chrome&copyts=1&mediaIndex=0&offset=0&path=%2Flibrary%2Fmetadata%2F53523&X-Plex-Token=asdasdasdasdaasdasd'.
     2 Ch, 44.1 KHz, 16:s:b

tizonia avatar Feb 18 '18 18:02 tizonia

When playing to a cast device, it's effectively creating a normal playback session as it would to any other Plex app - versus just transcoding and creating a universal URL to a media file.

Which means that in addition to just playing a single song, you can see the session status in other devices (Plex web), you can build playlists, shuffle stuff, and generally have more control over the Plex app.

You won't see this difference in logging the Plex Web app's JS output, as it's handled by the cast library separately. I've actually modified Plex Server JS files so that I can get it to output the full, proper JSON being sent to the Plex cast app.

Alternatively, baloob has details in his readme for controllers that tell how to capture packet data from Chrome when initiating playback, but it's a little tougher to grab and parse the JSON that way. But, effectively, if you log playback to a cast device from Plex.TV, you should see a call to /token or /security, and then another one to /playqueues. Re-create these calls to get the transient token and play queue ID, then ship that data to my Plex controller and you should have it. Looks like your current URL has most of the other stuff required - namely, the server ID and URL, offset, and path to the media. ;)

d8ahazard avatar Feb 18 '18 18:02 d8ahazard

@d8ahazard: Sorry, I think I've realized now. You think I'm using URLs from the Plex Web app. No, my app uses pkkid/python-plexapi to retrieve proper streaming URLs from the Plex server.

tizonia avatar Feb 18 '18 18:02 tizonia

Ah. Then PlexAPI I think has functions to queue media and grab transient tokens and stuff.

On Sun, Feb 18, 2018 at 12:44 PM, Tizonia [email protected] wrote:

@d8ahazard https://github.com/d8ahazard: Sorry, I think I've realized now. You think I'm using URLs from the Plex Web app. No, my app uses pkkid/python-plexapi to retrieve proper streaming URL from the Plex server.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/balloob/pychromecast/issues/146#issuecomment-366537396, or mute the thread https://github.com/notifications/unsubscribe-auth/ABjuNOoaBPXF3sNwx40cOdO-vhBZ9zdzks5tWG-UgaJpZM4LTpHE .

d8ahazard avatar Feb 18 '18 18:02 d8ahazard

Hi @tizonia - have you had any luck at playing Plex media IDs to ChromeCasts?

I feel I am close but the chromcast is coming back with "Something went wrong"

mattpurnell avatar Jun 27 '18 03:06 mattpurnell

@mattpurnell : This is not working for me yet, but I have not tried in a few months. The last time I tried, it seemed as if the Plex server refused to serve those URLs to the Chromecast. But this was purely an observation on my part as the same URLs would be happily served to any multimedia client running on the same machine where the URL was obtained (note: did not take Wireshark dumps or anything like that to corroborate).

tizonia avatar Jun 27 '18 10:06 tizonia

I got this working. Ill do some cleanup and post a updated controller.

Hellowlol avatar Jun 18 '19 16:06 Hellowlol

You may want to look at my repository flextv.bundle. I've had it a lot more functionality than what's here already.

On Tue, Jun 18, 2019, 11:30 AM Hellowlol [email protected] wrote:

I got this working. Ill do some cleanup and post a updated controller.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/balloob/pychromecast/issues/146?email_source=notifications&email_token=AAMO4NAZVGKGIR6ATART57DP3EERTA5CNFSM4C2OSHCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODX7GQ2Q#issuecomment-503212138, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMO4NACFJUMDVP7BL2QUBTP3EERTANCNFSM4C2OSHCA .

d8ahazard avatar Jun 18 '19 16:06 d8ahazard

Zomg, i checked that repo but i didnt realize you edited the sourcecode.. Good stuff :)

Hellowlol avatar Jun 18 '19 18:06 Hellowlol

If anybody want to test something that works direcly with plexapi you can try this branch. https://github.com/pkkid/python-plexapi/tree/chromecast

Dunno if it gets merged, but i plan to send a pr to pychromecast later.

Hellowlol avatar Jun 19 '19 00:06 Hellowlol

Hmm, this thread has been great at moving me along, @Hellowlol chromecast.py was very useful. I think I'm close but am looking for some advice. I wrote a simple script (below) to use both pychromecast and PlexAPi, the Plex app spins up, tries to play, then the app the hangs with the Plex-grey screen. I'm not sure why it crashes. It crashes to the point I have to load another app on the Chromecast (eg Youtube) before I can even try to cast against using the Android Plex app.

It will display the program info if I break the script at that point. But playing...any ideas from others who have gotten this working? Thanks.

import os
import time
import pychromecast
from pychromecast.controllers.plex import PlexController
from plexapi.server import PlexServer
from plexapi import utils

baseurl = 'http://192.168.1.20:32400'
token = 'xxxx'
plex = PlexServer(baseurl, token)

pc = PlexController()

chromecasts = pychromecast.get_chromecasts()
[print(cc.device.friendly_name) for cc in chromecasts]

cast = next(cc for cc in chromecasts if cc.device.friendly_name == "Living Room TV")
cast.register_handler(pc)
cast.wait()
print(cast.device)

videos = plex.library.section('Videos')

for show in videos.search(title='Mister'):                                                                                                                                                                                                 
    for episode in show.episodes():
        episode.reload()
        print(episode.title)
        print(episode.media)
        print(episode.getStreamURL())
        pc.show_media(episode)
        pc.play_media(episode)
#        pc.block_until_playing(episode)                                                                                                                                                                                                      
        break

print(pc.status)

while True:
    try:
        time.sleep(1)
    except KeyboardInterrupt:
        break

lairdm avatar Dec 22 '19 23:12 lairdm

I don't know what the issue is but this script will loop every search result in show then try to start playback on every single items. Its bound to mess up things. Try on one single item and use block_until_playing

Hellowlol avatar Dec 22 '19 23:12 Hellowlol

That's a fair critique, fortunately for me there was only one show containing "Mister" in the video collection. So it was only trying to play the first episode of that show (there's a break in the inner loop). I added a break to the outter loop too just to be safe, so it will only ever try one episode of the one show. No joy. Le sigh.

lairdm avatar Dec 23 '19 00:12 lairdm

Dunno, then. Been a while since is have used this, i dont know where my chromecast is but ill see if i cant find it and test after 🎄 .

Hellowlol avatar Dec 23 '19 01:12 Hellowlol

That would be appreciated if you or anyone else has time. I was wondering if it could be a Chromecast revision issue. This is a very old 1st gen Chromecast I picked up back when we were living in England.

lairdm avatar Dec 23 '19 01:12 lairdm

Hi - I have tried your code, @lairdm - but it's not working for me either, despite no errors from the request, and nothing conclusive in the Plex logs either.. even with verbose enabled. Just a grey/white

I did see: 'ERROR - TranscodeUniversalRequest: missing path argument' once, but I will be trying to repeat this over the next few days.

mattpurnell avatar Jan 09 '20 08:01 mattpurnell

Has anyone yet suceeded with this? I'm also only getting the Plex "Something went wrong"-error...

dulemis avatar Feb 29 '20 10:02 dulemis

Sadly no. I picked up a Roku at a Boxing Day sale which seems to be a lot more scripting friendly than the Chromecast. I have it load the Plex app then use the Plex API to play media on it.

lairdm avatar Mar 01 '20 22:03 lairdm