AndroidHDMI for Channels (ah4c): A virtual channel tuner using HDMI Encoder(s) + streaming stick(s)

worth trying these (i dont have spectrum creds to test myself)

adb shell am start -n com.TWCableTV/com.twc.android.ui.login.SplashScreen
am start -n com.TWCableTV/com.twc.android.ui.livetv.phone.LiveTvPhoneActivity --ei channelNumber 7 --ez initialLaunch true

What device did you install on? Because the actual app is not available as far as I know on Android TV devices so some people installed the mobile app and it doesn't work in the past at least.

Supposedly I think on April 18th it became available for the fire TV devices but I haven't checked into it yet.
Quick way to see if they have deep links available is to go to the spectrum website and see if you can't "cast" a channel directly to your device.

If I get a chance I'll try to look at a fire TV stick this weekend.

The Spectrum TV app is available for current FireTV devices. However, new Fire TV devices will not be Android-based,

It appears to be available for all Android TV devices; I have successfully installed and tested it on a Sony TV and two Nvidia Shields.

1 Like

That is great news about Android now.
I posted a link to Cordcutters earlier in the thread on Mar 31 about firetv support starting in April but they had no information about whether it would be made available on Android at the time.
@Pasker17 I just loaded the spectrum app on my onn google tv dongle and using my desktop i told it to cast a channel I was watching and it went directly to that channel stream on onn tv. So that means it does have deeplinking to the individual channels. Have you had a chance to look at the suggested format from @KineticMan ?
I will try and spend some time on this in the next few days.

Great news about deeplinking; I should have time to play with it over the weekend.

What's the best way to give feedback or contribute? Started playing around with this, and using the osprey scripts as a starting point, but the included example scripts do things that don't seem to make sense. For example, the prebmitune script runs an adbConnect function and then an adbWake function, but the adbConnect function already tries three times to do the wake. The bmitune script declares variables that it doesn't use, and runs methods that don't do anything as their result is also never used.

I suggested you start with scripts/osprey/dtvosprey primarily because they use the same remote control emulation of number presses you were talking about.

Over a number of years, people have adapted various previous scripts, and not always taken the time to remove unneeded functions or variables. You should create your own set of three scripts in a directory called scripts/<streaming device>/<streaming service>.

There's another set of scripts that may be a better model for what I suspect is the simplicity of your requirements. Check out scripts/allente/livetv. I helped someone create those a couple years ago, and they're some pretty basic scripts for sending number keycodes to tune -- which might be a better match for you.

And yes, please contribute back in the form mentioned above, and include your <streaming service>.m3u file as well.

4 Likes

Apologies if I've missed it in this thread or the documentation, but when are the prebmitune.sh and stopbmitune.sh scripts run? I assume the pre script runs when Channels tunes to an ah4c-managed channel from a non-ah4c managed channel? Then the tune script runs when Channels switches between different ah4c-managed channels? And then the stop script runs when Channels tunes away from an ah4c-managed channel to a non-ah4c-managed channel? Or is it more about timeouts, idle times, etc? Thanks.

It's nothing too complicated:
The value of $STREAMER_APP defines which set of scripts is run.
Each script must exist and be written in Bash.
All 3 scripts are run on each virtual tuning cycle.

Generally:
Use prebmitune.sh to confirm adb connectivity and wake your device (if needed).
Use bmitune.sh to do the virtual tuning.
Use stopbmitune.sh to stop the streaming and put your device to sleep (if needed).

Each script is passed the value of $TUNERx_IP and whatever the value is after the last slash in the URL for that virtual channel in the M3U. Note that for historical reasons those arguments switch order in bmitune.sh.

Super simple, but also very flexible, as you'll see if you explore the various scripts in the repo. As I understand your requirements, something like those that were done for scripts/allente/livetv may be about all you'll need. There's always an M3U file as well, for each set of scripts, so have a look at allente.m3u to model that.

1 Like

With the help of my new best friend, Claude, I was able to figure out the following regarding the Spectrum app for Android TV:

I was able to launch the application using:

adb shell am start -n com.spectrum.stva.androidtv/.ui.HostedMainActivity

After some tinkering, Claude determined that "there are no deeplink intent filters at all — no custom scheme, no HTTPS app links. This tells us the app handles navigation internally after launch, not via external URIs," and, "Since it's a WebView app, channel navigation almost certainly happens via JavaScript/web routing inside the WebView, not Android intents. The URI you pass gets handed to the web layer, which decides what to render."

After a few more tests, we determined that the app will tune using channel numbers. After launching the app, we were able to use ADB to tune like this:

# KEYCODE map for digits
# 0=7, 1=8, 2=9, 3=10, 4=11, 5=12, 6=13, 7=14, 8=15, 9=16

# Example: Tune to channel 20 (press 2, then 0)
adb shell input keyevent 9   # press "2"
adb shell input keyevent 7   # press "0"`

We also tried the following, but the app only received the last digit of the sent text:

# Channel 35
adb shell input text "35"`

Long story short, we created a script that works reliably using ADBTuner:

JSON{
    "name": "Spectrum TV",
    "author": "Custom",
    "version": "2.1",
    "description": "Tunes Spectrum TV via channel number keyevents. Set TARGET_URL_OR_IDENTIFIER to the channel number (e.g. 35 for CNN). Spectrum uses an internal WebView router with no deeplink support — channels are tuned via keyevents after app launch.",
    "uuid": "f4a7b2c9-d831-4e56-9f0a-7c3e8b1d2a45",
    "global_options": {
        "wait_for_video_playback_detection": true,
        "use_fixed_delay": false,
        "fixed_delay_seconds": 0,
        "wait_after_post_playback_start_commands_seconds": 0
    },
    "pre_tune_commands": [
        "input keyevent KEYCODE_MEDIA_STOP",
        "am force-stop com.spectrum.stva.androidtv",
        "input keyevent KEYCODE_HOME"
    ],
    "tune_commands": [
        "adbtuner_open_app com.spectrum.stva.androidtv",
        "sleep 8",
        "input keyevent KEYCODE_DPAD_CENTER",
        "for digit in $(echo '||TARGET_URL_OR_IDENTIFIER||' | grep -o '.'); do input keyevent KEYCODE_$digit; sleep 0.4; done",
        "sleep 1"
    ],
    "tune_match_text_commands": [
        {
            "match_text": [
                "who's watching",
                "choose an account",
                "edit profiles",
                "sign in"
            ],
            "commands": [
                "input keyevent KEYCODE_DPAD_CENTER"
            ],
            "start_checking_after_seconds": 3
        }
    ],
    "post_playback_start_commands": [],
    "post_tune_commands": [
        "input keyevent KEYCODE_MEDIA_STOP",
        "am force-stop com.spectrum.stva.androidtv",
        "input keyevent KEYCODE_HOME"
    ],
    "timed_keep_active_commands": []
}

It is slow, but it works.

I hope this somehow helps the community.

1 Like

Agreed! Just wanted to put this out there as a reference.

1 Like

Thanks, got it. Is there a best practice for whether or not to sleep the device as part of that cycle? Currently watching a channel and then going back to the Guide and choosing a different channel results in a full sleep-wake cycle which makes tuning the new channel quite slow. I feel like it would be nice to be able to have a delay, and only sleep the device after 5 minutes of no watching activity for example. That would allow more rapid tuning when changing between channels via the Guide.

Also I'm seeing that switching directly from one channel to another in Channels (without going back to the Guide) results in a "tuner in use" error because ah4c sees the new channel as a new tuning session, not a new tuning for the existing session.

1 Like

the priority is for recordings. changing the existing tune would make reliable recordings impossible.

yes, at least 2 tuners is highly recommended.

1 Like

Yeah...1 tuner won't cut it for channel surfing. If you're using a LinkPi @Lambers, there's an USB input which you can use as an extra tuner by getting an HDMI USB grabber

No -- that's definitely your choice. Some devices need to sleep or they're streaming 24x7, which isn't necessarily great if you have 5+ devices. :slight_smile:

It's not typical for this type of virtual tuning to be speedy. 3-5 seconds is rarefied air, 8-10 seconds more average, with 15 seconds needed for some scenarios.

This should be possible to script.

You definitely want multiple tuners with all of these virtual tuner solutions. Plus as mentioned by others, channel surfing can be done -- but don't expect a cable or satellite box type experience. DTV with Osprey boxes, or YTTV with the newest FireTV Cubes would get you close -- but otherwise you're looking 5-6 seconds minimum for typical virtual tuning.

1 Like

I am using the following after generating the directv m3u with olive tin. Some of it of course doesn't apply given the capture device you are using. Excuse the redundant commands where you see them. I just have not bothered to clean up.

bimtune.sh:

#!/bin/bash

callSign=$(echo $1 | awk -F~ '{print $1}')
contentID=$(echo $1 | awk -F~ '{print $2}')
tunerIP="$2"

# Map tuner IP to Magewell input
case "$tunerIP" in
    "192.168.1.130") streamPath="stream/0-1" ;;
    "192.168.1.131") streamPath="stream/0-2" ;;
    "192.168.1.132") streamPath="stream/0-3" ;;
    "192.168.1.133") streamPath="stream/0-4" ;;
    *) streamPath="stream/0-1" ;;
esac

encoderURL="http://192.168.1.188:6502/$streamPath"

adb -s $tunerIP shell am start -S -W \
  -a android.intent.action.VIEW \
  -d "dtvnow://deeplink.directvnow.com/play/channel/$callSign/$contentID"

# Wait until Magewell is receiving signal 
sleep 8

prebmitune.sh:

#!/bin/bash

TUNERIP="$1"

adb connect $TUNERIP

 #Check screen state
SCREEN=$(adb -s $TUNERIP shell dumpsys power | grep 'mWakefulness=' | awk -F= '{print $2}' | tr -d '[:space:]')
if [ "$SCREEN" != "Awake" ]; then
    adb -s $TUNERIP shell input keyevent KEYCODE_WAKEUP
    sleep 2
fi

adb -s $TUNERIP shell input keyevent KEYCODE_WAKEUP
adb -s $TUNERIP shell input keyevent KEYCODE_WAKEUP
adb -s $TUNERIP shell input keyevent KEYCODE_WAKEUP

stopbmitune.sh:

#!/bin/bash

TUNERIP="$1"

adb -s $TUNERIP shell "input keyevent KEYCODE_MEDIA_STOP"
adb -s $TUNERIP shell "input keyevent KEYCODE_MEDIA_STOP"
adb -s $TUNERIP shell "input keyevent KEYCODE_HOME"
adb -s $TUNERIP shell "input keyevent KEYCODE_HOME"

too much winning i guess.. lol
I have a 2x2 setup. identical except for the lower frame rate on my usb's.
I favorite movie and other 4k channels with the 2xHdmi set and I favorite the news and low res retroTv to the lower framerate 2xusb

I've actually been considering splitting them all out individually, but I bet it'd be a network disaster.

1 Like

I've been learning what that nature actually is recently.
groups in order Favorites, HD, SD, none
each group looks by source priority in reverse channel # order.

Yes definitely, and it makes sense with LinkPi's 5 tuners per encoder. I'll add that soon-ish.