Roku Deeplinks Tuner

I pulled an old Roku out and was messing around with the External Control Protocol (ECP) on it and was able to send Deeplinks via curl commands to the Roku and open apps to a the channel I wanted on YouTube TV and Philo apps. I searched GitHub to see if anyone has made a Deeplinks tuning script and could not find anything specifically made to do this. I saw that Roku does not want people making a Roku Channel (app) that uses the ECP controls but nothing about external applications using it.

So my question is, has anyone tried to make a Roku script similar to ADBTuner and if so, what issues did you encounter?

No need to "create" anything. If you can make it work with Curl commands then I believe you should be able to just use ADBTuner with custom /configurations
Or definitely AH4C (might need to use the AppleTV version so it doesn't bother with ADB stuff) with your custom "Roku" scripts.

I gave up on using Rokus last year for my use case.
At least the cheap rokus I bought to experiment with always seemed REALLY slow and underpowered.
I was researching this for Spectrum App on Roku. Looked into it because I assume Spectrum and Amazon/Google were fighting over how to divide up app money and removed the app from those platforms. After talking with Spectrum and Roku found out that Spectrum doesn't support DeepLinks on Roku. So I just moved to Used ATVs from Ebay and haven't looked back. (Not an Apple Fan Boy...This was the first time I owned any Apple Products.)

I already built a backend that sends a M3U playlist of the stream from a Roku connected to an HDMI Encoder and changes channels with Deeplinks. I have only tested it with Philo and YTTV apps. Both work well. The Deeplinks format for Roku is the same for all the apps that support Deeplinks. On VLC it works flawlessly. In Channels, I have a few little issues to work out with stream quality, but it does play in Channels. I figured having more options would be a good thing. As soon as my new encoder arrives, I will post some videos of it in action.

I cant argue with having choices. :+1:

If it can use custom user scripts...
And if I have the time when you get it working and posted I might give it a try with a spare ATV for Spectrum

Here is a video of the Roku ECP Tuner script. It is still early and I have a lot of work to do on it, but it is a good proof of concept.

This could be really nice for people with spectrum tv. Spectrum doesn’t have an app for android tv devices just Roku and Apple TV.

I hope the Spectrum App on Roku supports Deeplinks. I will start testing other apps once I get the little bugs worked out. Here's a better video from my phone.
edit: The video recorded with audio out of sync. The actual playback was synced correctly.

1 Like

Looks like it is tuning those pretty good! Great Job on this.
Unless they changed it in the last year or so, Spectrum App on Roku does NOT support deeplinks. I doubt they will bother since they are trying to push everyone to use their Xumo devices.
If you are writing your app to take Curl commands and I can install pyatv on it, I will be able to send deeplink commands to ATVs.
I think I probably have a Roku around somewhere and do use Philo and PlutoTv.

I spent a few hours this morning looking at that. I came across your post on the Roku page about it. That sucks, but that is also why I don't use Spectrum anymore. They have always tried to make it hard on the subscribers with their apps. They treat it as a burden instead of embracing usability.

I agree Spectrum sucks...Spectrum Acct belongs to some older family members and they just aren't interested in moving to YoutubeTV or anything else. :man_shrugging:
Took 15 years for some other family members to finally have enough of DirecTv screwing them year after year for them to move on.

I have an early release that can be tested. It has a long way to go, but does offer some basic functionality. This is not ready for production use and is only recommended for testing purposes!

Step 1: Find Your Roku Device's IP Address
You need the IP address of your Roku device to send ECP commands to it.
On your Roku remote, press the "Home" button.
Navigate to "Settings".
Select "Network".
Select "About".
Write down the "IP Address" displayed. It will look something like 192.168.1.100.

Step 2: Enable "Control by Mobile Apps" (If not already enabled)
For some ECP commands (especially keypresses), Roku OS 14.1 and later require the "Control by mobile apps" setting to be "Enabled".
On your Roku remote, press the "Home" button.
Navigate to "Settings".
Select "System".
Select "Advanced system settings".
Select "Control by mobile apps".
Change the setting to "Enabled". You might get a warning; select "Yes, allow".

To find the ID numbers for the Roku apps:

curl http://YOUR_ROKU_IP:8060/query/apps

I added a few optional fields this morning. It now has the ability to provide a tuning delay, time shift or select key press if needed. It has worked well in my tests.

I also turned the testing logging off by default. If anyone wants to view troubleshooting debug logging, add -e ENABLE_DEBUG_LOGGING=true to the run command to enable it.

A couple of years ago I looked into adding support for Roku to ADBTuner, but ended up bailing on the idea solely for performance reasons. The devices I had tried were really slow and, at least at the time, Roku OS forced a restart of the target app whenever deep linked content was loaded. I was looking at 40+ seconds to load a stream. :frowning:

Everything lines up well for Roku to be the best choice for something like this. They offer a fully supported API (not just for loading content, but for determining playback status), a desktop app for testing/discovering deep links, etc. They are the only company in this space that seems to care at all about third-party integrations. Hopefully their devices are a bit faster these days.

Good luck with this, and thanks for sharing. This could be another great option for getting content into Channels DVR!

1 Like

Thank you. They must have changed something for the better because the load times are good. The main issue I found was an invalid byte in chunk length error. I think it has something to do with the HDCP handshake but not sure. I just re-encoded the stream to get a clean feed to Channels. Other than that, it works well.

Great! It's good to hear that performance has improved.

I've never run into that specific issue, but if it helps, something like this should drop into your app to provide a proxied video stream if you want to make re-encoding optional. These cheap encoders do weird things and this way of handling them seems to be pretty reliable.

httpx would need to be added as a dependency, or you could probably rewrite this to use requests instead.

import httpx

def proxy_stream_generator(encoder_url, roku_ip_to_release):
    try:
        transport = httpx.HTTPTransport(retries=5)
        timeout = httpx.Timeout(15.0)

        headers = {
            "accept": "*/*",
            "range": "bytes=0-",
        }

        client = httpx.Client(
            timeout=timeout,
            transport=transport,
            headers=headers,
            follow_redirects=True,
        )

        # allow for retries as some endpoint devices tend to drop connections when they start streaming
        for i in range(10):
            with client.stream("GET", encoder_url) as r:
                for data in r.iter_bytes():
                    yield data

    except Exception as e:
        logging.error(f"Error in proxy_stream_generator: {e}")

    finally:
        release_tuner(roku_ip_to_release)
        logging.info(f"Released tuner {roku_ip_to_release} after stream completion.")

Thank you, I'll check it out and see how it works. These no name encoders are a not the best, but they are cheap. I always figure if I can get it to work on junk, the good stuff should be cake. :rofl:

The httpx proxy transport helper definitely improved the stability of the corrupt stream in Channels. I ran the encoder stream through ffprobe and the stream is poorly constructed, with desynchronized audio/video packets and missing metadata. It's a mess. I'm waiting on a Link Pi encoder to be delivered and hopefully it will provide a cleaner stream. Thanks again.

Yeah. All of these encoders are quirky and hilariously insecure, but they get the job done.

Made some good progress on the project. I added a new stream handling mode to it called remux that takes the original audio and video streams from your encoder and puts them into a new, clean container file without changing the streams themselves. I also modified the reencode mode to only re-encode audio which significantly reduces the CPU load while providing a clean and steady stream to Channels DVR. The default mode is still proxy which should work fine if your encoder provides a clean stream to the bridge.

If you were to have asked me a few days ago if I thought this Roku Tuner would ever work correctly, I would have said I don't know. After the last few updates and tests, I would say I think it will work. Hopefully the tests and improvements continue to progress in a positive way.

I moved the project to Beta as it is more stable and now has a frontend. The installation has been simplified and I have started to add more documentation and guides to help users get it up and running.

2 Likes