i8beef / node-red-contrib-castv2

MIT License
22 stars 14 forks source link

add TuneIn Support #33

Closed cru8602 closed 3 years ago

cru8602 commented 3 years ago

Hey, would it be possible to add TuneIn to the supported apps in order to start a Radio playback? Till now I just send the URL of the webradio I wanted to listen to to the google home, but since I have upgraded my setup with a google nest hub the default media player is blocking the screen while the radio is playing witch isn't what I want to see. Also the default media player stops playback when it's not in foregraund unlike the TuneIn app (or others like spotify). So a TuneIn integration would be realy greate a this point!

i8beef commented 3 years ago

It looks like it supports media CONTROL commands, but it also looks like they probably implement their own LOAD commands (most apps do this for authentication purposes, and because they usually control both the chromecast app, AND the application that's sending the cast... ergo its rare to find documented specifications on these). I'm not inclined to implement this for you (there are THOUSANDS of apps, I can't support all of them), but I WILL accept a PR if you get it working.

What that would take:

  1. Identify the appId(s) and the namespaces that a TuneIn controller would have to support. You can start the app, and examine the published device status from the node for the application definition.
  2. Create a Receiver / Adapter and wire them in. Easiest way would be to take on of the "control only" ones like the Netflix one and copy them. This is the skeleton solution that should at least allow it to launch / join a session and control active playback.
  3. Figure out the app specific load implementation. You can kind of look at the Spotify receiver / controller for an idea of what needs done BASICALLY... but of course the actual implementation will be completely different. This is always rough because you basically need either (a) documentation on what needs done, (b) a working sample you can steal from, or (c) to capture the communication between your phone app and the chromecast to try and reverse engineer their protocol.

I can't find any obvious examples to point you at, but it LOOKS LIKE there are "namespaces" for TuneIn like "urn:x-cast:com.tunein.cast.init" and "urn:x-cast:com.tunein.cast.initUrl", one of which you'd have to make a TuneIn controller LOAD would use. Unfortunately though, I have no idea what the format for that load command would be.

cru8602 commented 3 years ago

OK, I guess I'll have a lot of research to do. Unfortunately my programming skills are only slightly above noob so this may take some time witch is more worse for me than for you, but I'll do my very best.

ChillXXL commented 3 years ago

CONTROL TuneIn error

While playing a TuneIn radio station a PAUSE command will not pause the playback because the node rejects: "

image

Node output: image

What could be wrong? Other commands like volume will work fine.

Also tried to pause form other apps like Google Home app and they will pause (and play) the stream correct.

i8beef commented 3 years ago

TuneIn is not an actually supported app for this node (yet, if OP comes through on changes 😄). The underlying library (castv2-client) ties my hands a bit here, and while I'd LIKE to be able to control any supported "channel" (Namespaces in the above response), I'm limited to controlling any supported APP (which controls various channels) instead. Media controls being the obvious "globally supported" one we'd all like. I kicked the idea of a "generic receiver" at one point, but ran into trouble somewhere that I forget which was an issue with the underlying implementation that I couldn't get around.

There IS an underlying library UNDER that (castv2) which has more direct control of the "channels" themselves, but that's basically a complete overhaul of this node and all of its existing assumptions / functionality to get there... that's not completely out of the question one day when I'm bored and have nothing else going on because (a) I would like that "generic media control" capability too, and (b) I've already replaced about half of the classes in the castv2-client library anyway due to outstanding bugs and memory leaks, so I'm literally about 50% there to writing my own client class anyway and abandoning that.

But its also fairly non-trivial and basically a THIRD rewrite of this node to get there.

Edit: Also the command that DID work, volume, is a "platform" command that doesn't go to the "app client", but to the cast device itself. i.e., as long as you have a connection, those will work, but "media commands" require an active application client to run.

cromatox commented 3 years ago

Hi All! I have added a pull request for a TuneIn receiver/adapter for simple media playback control.

i8beef commented 3 years ago

Looks ok. Pushed 3.2.8 out. See if thats working ok for you, and feel free to close out when satisfied.

cromatox commented 3 years ago

Hi i8beef, 3.2.8 works for me, thanks!!

ChillXXL commented 3 years ago

Works great! Thanks a lot cromatox & i8beef.

cru8602 commented 3 years ago

I have not tried the new verison yet but does "media control only" mean, that I can only pauss a runing stream and resume the playback later or can I also start a new stream on an idle google home/chromecast device? how would a propper input to the node looke like?

cromatox commented 3 years ago

I have not tried the new verison yet but does "media control only" mean, that I can only pauss a runing stream and resume the playback later or can I also start a new stream on an idle google home/chromecast device? how would a propper input to the node looke like?

Media control only means that the media commands GET_STATUS, PLAY, STOP, PAUSE, SEEK works with TuneIn Radio started by voice, mobile app or any other application through Chromecast. You can not start a TuneIn radio stream, but you can use the Default Media Receiver with the radio stream URL directly (see README).

alsak0de commented 3 years ago

you guys are good! (thanks a lot) could you elaborate on how to structure msg-in payload?

i8beef commented 3 years ago

For media commands? Just like all the rest in the documentation. Once the node is connected to the app running on the device, the generic media commands are basically the same no matter which (supported) receiver is running.

i8beef commented 3 years ago

Note I just released 4.0.0 which SHOULD support generic media controls on ANY receiver now that claims to support it automatically... that means I killed the specific TuneIn controller, etc. for now as the only part that gave us was the media control anyway...

If someone pursues the media load commands, etc. for TuneIn, those files are in the history at least to point to still as a basic implementation to be expanded on (so not wasted effort).

i8beef commented 3 years ago

Closing as stale.