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

Playback support? #41

Open
d8ahazard opened this issue Oct 2, 2021 · 14 comments
Open

Playback support? #41

d8ahazard opened this issue Oct 2, 2021 · 14 comments
Assignees
Labels
enhancement New feature or request

Comments

@d8ahazard
Copy link

Hey there, does this support playback control on various devices?

@jensenkd
Copy link
Owner

jensenkd commented Oct 2, 2021 via email

@d8ahazard
Copy link
Author

Not yet, but let's add it. What's your use case?

On Sat, Oct 2, 2021, 3:16 PM d8ahazard @.***> wrote: Hey there, does this support playback control on various devices? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#41>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABJWDOPMNGYM7P3BEC4FKLUE5SABANCNFSM5FGYD67Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

LOL.

Takes deep breath...

So, about two years ago, I had a fully-working service for Google Assistant called "Flex TV" that would allow people to control playback (and other things) of their Plex instance.

"Hey, Google, Tell Flex TV to play Batman Begins on the living room TV" or "Hey Google, Ask Flex TV to play the latest episode of Foundation".

This would bounce a command from Google to a public webserver/domain I have, and then use linked Plex creds to beam that command to the user's server, do a media lookup, and then fire playback of the relevant media (as best as could be found).

But, this was written in PHP, meaning Google's support libraries for Assistant + PHP were severely lacking, so I gave up supporting it in that form.

To further complicate things, I'm still a few months from completion of my current project "Glimmr". But, once I've got that wrapped, up, I plan on re-writing Flex TV in dotnet. As such, I found myself looking at the various available support libraries for dotnet for all the things I want to do, and...well...here we are.

So, I'd totally be open to answering questions on what I sussed out to make it work in PHP...I'm also a Plex Ninja, so I can get a bit more direct answer to a lot of questions regarding undocumented API stuff if needed. But, until I get Glimmr done and shipped, I'd be doing a lot of people a disservice if I hopped to another project now.

https://github.com/d8ahazard/FlexTV

@jensenkd
Copy link
Owner

jensenkd commented Oct 6, 2021

Sounds good. I have a potential use case to leverage that functionality as well.

Do you have any insight on the api to play media on a specific player? I can start out by building some unit tests around those api calls.

@d8ahazard
Copy link
Author

Sounds good. I have a potential use case to leverage that functionality as well.

Do you have any insight on the api to play media on a specific player? I can start out by building some unit tests around those api calls.

Indeed I do. It's...a process, and (hopefully), it may have changed now so we can route commands directly through Plex.tv, versus an individual server.

As it's been a while, I'm a bit out of touch and don't directly recall the specifics of everything...but if you look here:

https://github.com/d8ahazard/FlexTV/blob/247d30d6c6737e517862710188b302d6a72a673c/api.php#L2704

The "sendMedia" method is my wrapper for doing all the things. The biggest part is ensuring you get the header right, but there are also other requisites.

Basically, you need to fetch a "transient token" from the server for every media play command.
You also need to keep a rolling command counter so that the server stays "in sync" with what you're sending.
The rest of it is ensuring you have the proper information on the media object (from Library) and server object, and are sending it to the right place.

Let me know how you get on with the code example. It's old AF, written in (messy) PHP, and more importantly....I've learned a lot about creating individual classes of objects so that it's a lot easier to pass data around than when I wrote this. BUT, the gist of the commands are still there...it's just deciphering my spaghetti-code that'll be the tricky part.

Also - you'll see I've got some stuff for controlling any chromecast devices as well. My intention is to write cc support into the new version of my app. BUT, if you wanted to go the whole gamut and incorporate chromecast stuff as well, I can probably help you with that too. ;)

@jensenkd jensenkd self-assigned this Oct 6, 2021
@jensenkd jensenkd added the enhancement New feature or request label Oct 6, 2021
@jensenkd
Copy link
Owner

jensenkd commented Oct 6, 2021

@d8ahazard
Copy link
Author

For future reference: https://www.reddit.com/r/PleX/comments/dox9a5/creating_a_play_queue_and_sending_it_to_a_player/

Yeah, that looks familiar!

Also, the references listed from Github - those are part of what I used to write Flex TV.

BUT - the bit about only being able to control devices on the LAN isn't entirely true. You can trigger playback via the server on other networks, depending on the client and some other stuff. As that doc is over 2 years old, I'd consider it a starting point, versus the definitive reference.

A lot of what I figured out was done by using the web client and inspecting the actual data in and out for various playback commands.

@jensenkd
Copy link
Owner

jensenkd commented Oct 6, 2021

yep..I've got it creating playqueues and working on sending it to client player. It should work for any client registered with the server. I'll test it both internally and externally.

@d8ahazard
Copy link
Author

yep..I've got it creating playqueues and working on sending it to client player. It should work for any client registered with the server. I'll test it both internally and externally.

Sweet!

What are your thoughts on controlling Cast devices? While Cast might technically be out-of-scope, Plex uses their own cast "application", so technically, you would still be controlling Plex software...albeit using a separate protocol, etc.

@jensenkd
Copy link
Owner

jensenkd commented Oct 6, 2021

certainly interested in looking at that after getting this piece fully implemented.

@d8ahazard
Copy link
Author

d8ahazard commented Oct 6, 2021

certainly interested in looking at that after getting this piece fully implemented.

I was looking at this library for that feature in dotnet:

https://github.com/kakone/GoogleCast

And, the original library I was using was "pyChromecast", which I used in a helper plugin for Plex I wrote.

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

Plex has said that they'd eventually be killing support for server-side plugins...but two years later, and they still haven't, and last time I asked the developers, they said they still had no timeline for removing it...

So, option A. would be to just leverage this existing API functionality and use the extension(s) I added to the server to do cast control.

Option B. would be to use native methods and ditch the plugin. In which case, you'd probably want to refer to the source for the plex controller in PyChromeCast.

https://github.com/home-assistant-libs/pychromecast/blob/master/pychromecast/controllers/plex.py

@jensenkd
Copy link
Owner

jensenkd commented Oct 7, 2021

I was successfully able to submit a play request via server proxy to my phone. It only plays when my phone is on the LAN though.

"the bit about only being able to control devices on the LAN isn't entirely true. You can trigger playback via the server on other networks, depending on the client and some other stuff."

I'll have to find some more details around this.

@d8ahazard
Copy link
Author

I was successfully able to submit a play request via server proxy to my phone. It only plays when my phone is on the LAN though.

"the bit about only being able to control devices on the LAN isn't entirely true. You can trigger playback via the server on other networks, depending on the client and some other stuff."

I'll have to find some more details around this.

Let me ask the developers...

@obsidiangroup
Copy link

Just wondering, has there been any movement on this? I too am just finding this project, and looking at how to best use this.

@jensenkd
Copy link
Owner

No but if you'd like to tackle it, I'd certainly be able to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants