ADBTuner: A "channel tuning" application for networked Google TV / Android TV devices

After a false start (I had made a change, but didn’t update the device IP :man_facepalming: ), I had another non-launch. Here’s the log:


2023-08-20 18:42:39.734 - server - Reserved tuner 4
2023-08-20 18:42:39.734 - server - Using tuner id: 4
2023-08-20 18:42:39.734 - uvicorn.access - 192.168.6.248:37094 - "GET /stream/8 HTTP/1.1" 307
2023-08-20 18:42:39.736 - server - Tuner: Tuning to LIFECHD on ChromeCast 1
2023-08-20 18:42:39.737 - lib.adb - ADB: Connecting to device (attempt 1).
2023-08-20 18:42:39.796 - lib.adb - ADB: Connected.
2023-08-20 18:42:39.797 - lib.adb - ADB: 192.168.6.199 - dumpsys display
2023-08-20 18:42:39.859 - lib.adb - ADB: 192.168.6.199 - getprop ro.build.version.release
2023-08-20 18:42:39.902 - lib.adb - ADB: Android Version: 12.0.
2023-08-20 18:42:39.902 - lib.adb - ADB: 192.168.6.199 - pm list packages -3
2023-08-20 18:42:39.977 - lib.adb - ADB: 192.168.6.199 - pidof com.fubo.firetv.screen
2023-08-20 18:42:40.091 - lib.adb - ADB: Stopping media playback.
2023-08-20 18:42:40.091 - lib.adb - ADB: 192.168.6.199 - input keyevent KEYCODE_MEDIA_STOP
2023-08-20 18:42:40.174 - lib.adb - ADB: Force stopping com.fubo.firetv.screen.
2023-08-20 18:42:40.174 - lib.adb - ADB: 192.168.6.199 - am force-stop com.fubo.firetv.screen
2023-08-20 18:42:40.390 - lib.adb - ADB: 192.168.6.199 - am start -a android.intent.action.VIEW -d "https://link.fubo.tv/al1%3Fv%3D1%26a%3Dplay%26t%3Dchannel%26channel_id%3D93254" com.fubo.firetv.screen
2023-08-20 18:42:49.261 - server - Tuner: Compatibility Mode - Stream released after 9.53 seconds. Display was on, application (com.fubo.firetv.screen) was running.
2023-08-20 18:42:49.261 - lib.adb - ADB: Closing connection - 192.168.6.199
2023-08-20 18:42:49.261 - uvicorn.access - 192.168.6.248:37094 - "GET /stream/4/8 HTTP/1.1" 200
2023-08-20 18:42:49.265 - root - Tuner: Stream open (attempt 1).
2023-08-20 18:42:49.274 - httpx - HTTP Request: GET http://192.168.6.198/ts/1_0 "HTTP/1.0 200 Ok"

Hopefully there’s something that offers a clue!

I tried this update and for me it is not working. It looks like it loads a channel up properly in the HDHR and waits for the video, but then before displaying the video, it reconnects, and on the firestick side I can see the HDHR app close then open again and clicking on the correct channel, rinse and repeat.

1 Like

I am seeing the same thing more or less.

1 Like

I do not know if this helps but there is a bug when tuning the First Channel in the HDHomerun APP using ADB . I also found out it works better not using the Slice guide ....

My Script when tuning the very first Channel on the HDHomeRun web page it does a pad up then enter ....

set first=2.1

if "%channel%" == "%first%" (
    set line=%line%;input keyevent 111; sleep 0.25;input keyevent 19 66
) else (
    set line=%line%;input keyevent 111; sleep 0.25; input keyevent 66
)

Full Script Below.

@echo off

setlocal
set device=192.168.50.243:5555
SET PATH=%PATH%;C:\platform-tools\
set first=2.1

SET "var="&for /f "delims=0123456789." %%i in ("%1") do set var=%%i
if defined var (
    echo "error:  invalid character"
    goto :ends
)

set line=
set channel=%1
set /a counter=0

:loop
    set /a counter += 1
    if %counter% EQU 2 (
        set line=%line%;input keyevent
    )
    set digit=%channel:~0,1%
    set channel=%channel:~1%
    if "%digit%" NEQ "." (
        if "%line%" == "" (
            set line=shell input keyevent KEYCODE_%digit%;sleep 1.0
        ) else (
            set line=%line% KEYCODE_%digit%
        )
    ) else  (
        set line=%line% KEYCODE_PERIOD
    )
if NOT "%channel%" == "" goto loop
set channel=%1
if "%channel%" == "%first%" (
    set line=%line%;input keyevent 111; sleep 0.25;input keyevent 19 66
) else (
    set line=%line%;input keyevent 111; sleep 0.25; input keyevent 66
)

if %counter% gtr 6 (
    echo "error: max 6 characters"
    goto :ends
)

adb connect %device% >NUL
set ret=%errorlevel%
if "%ret%" NEQ "0" (
    echo "error: adb not found"
    goto :ends
)

adb -s %device% shell "dumpsys power | grep =Awake" >NUL
set ret=%errorlevel%
if "%ret%" == "1" adb -s %device% shell input keyevent KEYCODE_WAKEUP ; sleep 2

adb -s %device% shell am force-stop com.silicondust.view >NUL

adb -s %device% shell pidof com.silicondust.view >NUL
set ret=%errorlevel%
if "%ret%" == "0" goto home:
    adb -s %device% shell am force-stop com.silicondust.view >NUL
    adb -s %device% shell sleep 1
    adb -s %device% shell am start -W -n com.silicondust.view/.App >NUL 2>NUL
    adb -s %device% shell sleep 6
    goto :adbtune

:home
    adb -s %device% shell "am start -W -n com.silicondust.view/.App | grep -q WARM"
    set ret=%errorlevel%
    if "%ret%" == "0" (
        adb -s %device% shell sleep 4
    )

:adbtune

adb -s %device% shell sleep 0.5; input keyevent 19 19 19;sleep 0.5; input keyevent 21 21 21 66

adb -s %device% %line%

curl -s http://192.168.50.242:8086/8.ts

adb -s %device% shell input keyevent 4; am force-stop com.silicondust.view >NUL

:ends

Exit

Thanks for the feedback. I pushed an update that reverts the experimental HDHomeRun App support back to where it was at first. I will revisit at another time.

In this version, tuning was/is far more reliable when you can tune to a specific sub-channel (ex 11.1) versus cable TV channels without a sub-channel.

Edit: If you have single digit cable channel numbers that won't load, try entering them in ADBTuner with a leading zero (ex. 05) and let me know if that helps.

For those who had issues if you could share any logs you have from failed tunes and let me know what device(s) you had issues with that would be great. Are you saying the entire HDHomeApp was closing after tuning the channel?

Thanks for sharing. This idea won't work with ADBTuner as it will never know what the "first" channel is.

I believe that pausing first bypasses this and some other issues without having to have advance knowledge about the user's channel configuration, but requires unpausing the video if the channel tuned was the channel that autoplayed when the app opened. I put a lot of effort into determining the proper actions based on log data and other clues, but it seems something is still not right.

I found the other guide to not be without its own quirks so I stuck with the slice guide as its the default. I will of course reconsider that if/when I review this again. Thanks.

1 Like

Will try it in the morning ... Thanks.

Here are my logs for trying to tune to one of the channels, this is before updating it back. I will actually wait till tomorrow to update it again in case you need any more logs.

2023-08-20 20:34:20 2023-08-21 03:34:20.667 - server - Reserved tuner 1
2023-08-20 20:34:20 2023-08-21 03:34:20.667 - server - Using tuner id: 1
2023-08-20 20:34:20 2023-08-21 03:34:20.667 - uvicorn.access - 172.19.0.1:56006 - "GET /stream/11 HTTP/1.1" 307
2023-08-20 20:34:20 2023-08-21 03:34:20.732 - server - Tuner: Tuning to NBC (KPNX) on FireStick
2023-08-20 20:34:20 2023-08-21 03:34:20.735 - lib.adb - ADB: Connecting to device (attempt 1).
2023-08-20 20:34:20 2023-08-21 03:34:20.944 - lib.adb - ADB: Connected.
2023-08-20 20:34:20 2023-08-21 03:34:20.944 - lib.adb - ADB: 172.16.5.12 - dumpsys display
2023-08-20 20:34:21 2023-08-21 03:34:21.038 - lib.adb - ADB: 172.16.5.12 - getprop ro.build.version.release
2023-08-20 20:34:21 2023-08-21 03:34:21.086 - lib.adb - ADB: Android Version: 7.0.
2023-08-20 20:34:21 2023-08-21 03:34:21.086 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_WAKEUP
2023-08-20 20:34:22 2023-08-21 03:34:22.770 - lib.adb - ADB: 172.16.5.12 - pm list packages -3
2023-08-20 20:34:24 2023-08-21 03:34:24.428 - lib.adb - ADB: 172.16.5.12 - pidof com.silicondust.view
2023-08-20 20:34:24 2023-08-21 03:34:24.498 - lib.adb - ADB: Stopping media playback.
2023-08-20 20:34:24 2023-08-21 03:34:24.498 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_MEDIA_STOP
2023-08-20 20:34:25 2023-08-21 03:34:25.861 - lib.adb - ADB: Force stopping com.silicondust.view.
2023-08-20 20:34:25 2023-08-21 03:34:25.861 - lib.adb - ADB: 172.16.5.12 - am force-stop com.silicondust.view
2023-08-20 20:34:27 2023-08-21 03:34:27.068 - lib.adb - ADB: 172.16.5.12 - am start -a android.intent.action.VIEW com.silicondust.view/.App
2023-08-20 20:34:34 2023-08-21 03:34:34.171 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_MEDIA_PAUSE
2023-08-20 20:34:37 2023-08-21 03:34:37.110 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_1
2023-08-20 20:34:38 2023-08-21 03:34:38.876 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_2
2023-08-20 20:34:40 2023-08-21 03:34:40.843 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_ENTER
2023-08-20 20:34:43 2023-08-21 03:34:43.630 - lib.adb - ADB: 172.16.5.12 - pidof com.silicondust.view
2023-08-20 20:34:43 2023-08-21 03:34:43.695 - server - Tuner: Application PID: 24207
2023-08-20 20:34:43 2023-08-21 03:34:43.696 - server - Tuner: Checking playback status.
2023-08-20 20:34:43 2023-08-21 03:34:43.745 - server - Tuner: Waiting 5 seconds to allow sleeping device to setup.
2023-08-20 20:34:48 2023-08-21 03:34:48.746 - server - Tuner: Compatibility Mode - Stream released after 28.02 seconds. Display was off, application (com.silicondust.view) was closed.
2023-08-20 20:34:48 2023-08-21 03:34:48.747 - lib.adb - ADB: Closing connection - 172.16.5.12
2023-08-20 20:34:48 2023-08-21 03:34:48.748 - server - http disconnect
2023-08-20 20:34:48 2023-08-21 03:34:48.753 - lib.adb - ADB: Connecting to device (attempt 1).
2023-08-20 20:34:48 2023-08-21 03:34:48.821 - root - Tuner: Stream open (attempt 1).
2023-08-20 20:34:48 2023-08-21 03:34:48.835 - lib.adb - ADB: Connected.
2023-08-20 20:34:48 2023-08-21 03:34:48.835 - lib.adb - ADB: Stopping media playback.
2023-08-20 20:34:48 2023-08-21 03:34:48.835 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_MEDIA_STOP
2023-08-20 20:34:48 2023-08-21 03:34:48.848 - httpx - HTTP Request: GET http://172.16.5.53/ts/1_0 "HTTP/1.0 200 Ok"
2023-08-20 20:34:49 2023-08-21 03:34:49.985 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_MEDIA_PAUSE
2023-08-20 20:34:50 2023-08-21 03:34:50.838 - server - No tuners available.
2023-08-20 20:34:50 2023-08-21 03:34:50.840 - uvicorn.access - 172.19.0.1:50760 - "GET /stream/11 HTTP/1.1" 404
2023-08-20 20:34:51 2023-08-21 03:34:51.136 - lib.adb - ADB: Force stopping com.silicondust.view.
2023-08-20 20:34:51 2023-08-21 03:34:51.137 - lib.adb - ADB: 172.16.5.12 - am force-stop com.silicondust.view
2023-08-20 20:34:52 2023-08-21 03:34:52.455 - lib.adb - ADB: Closing connection - 172.16.5.12
2023-08-20 20:34:52 2023-08-21 03:34:52.456 - server - Released tuner 1
2023-08-20 20:34:52 2023-08-21 03:34:52.456 - server - Tuner: Cleanup complete. FireStick (NBC (KPNX))
2023-08-20 20:34:52 2023-08-21 03:34:52.936 - server - Reserved tuner 1
2023-08-20 20:34:52 2023-08-21 03:34:52.936 - server - Using tuner id: 1
2023-08-20 20:34:52 2023-08-21 03:34:52.936 - uvicorn.access - 172.19.0.1:34666 - "GET /stream/11 HTTP/1.1" 307
2023-08-20 20:34:52 2023-08-21 03:34:52.950 - server - Tuner: Tuning to NBC (KPNX) on FireStick
2023-08-20 20:34:52 2023-08-21 03:34:52.954 - lib.adb - ADB: Connecting to device (attempt 1).
2023-08-20 20:34:53 2023-08-21 03:34:53.038 - lib.adb - ADB: Connected.
2023-08-20 20:34:53 2023-08-21 03:34:53.038 - lib.adb - ADB: 172.16.5.12 - dumpsys display
2023-08-20 20:34:53 2023-08-21 03:34:53.115 - lib.adb - ADB: 172.16.5.12 - getprop ro.build.version.release
2023-08-20 20:34:53 2023-08-21 03:34:53.154 - lib.adb - ADB: Android Version: 7.0.
2023-08-20 20:34:53 2023-08-21 03:34:53.154 - lib.adb - ADB: 172.16.5.12 - pm list packages -3
2023-08-20 20:34:54 2023-08-21 03:34:54.566 - lib.adb - ADB: 172.16.5.12 - pidof com.silicondust.view
2023-08-20 20:34:54 2023-08-21 03:34:54.617 - lib.adb - ADB: Stopping media playback.
2023-08-20 20:34:54 2023-08-21 03:34:54.618 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_MEDIA_STOP
2023-08-20 20:34:55 2023-08-21 03:34:55.929 - lib.adb - ADB: Force stopping com.silicondust.view.
2023-08-20 20:34:55 2023-08-21 03:34:55.929 - lib.adb - ADB: 172.16.5.12 - am force-stop com.silicondust.view
2023-08-20 20:34:57 2023-08-21 03:34:57.050 - lib.adb - ADB: 172.16.5.12 - am start -a android.intent.action.VIEW com.silicondust.view/.App
2023-08-20 20:35:04 2023-08-21 03:35:04.156 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_MEDIA_PAUSE
2023-08-20 20:35:06 2023-08-21 03:35:06.873 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_1
2023-08-20 20:35:08 2023-08-21 03:35:08.624 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_2
2023-08-20 20:35:10 2023-08-21 03:35:10.538 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_ENTER
2023-08-20 20:35:13 2023-08-21 03:35:13.377 - lib.adb - ADB: 172.16.5.12 - pidof com.silicondust.view
2023-08-20 20:35:13 2023-08-21 03:35:13.425 - server - Tuner: Application PID: 24690
2023-08-20 20:35:13 2023-08-21 03:35:13.425 - server - Tuner: Checking playback status.
2023-08-20 20:35:14 2023-08-21 03:35:14.993 - server - Tuner: Compatibility Mode - Stream released after 22.04 seconds. Display was on, application (com.silicondust.view) was closed.
2023-08-20 20:35:14 2023-08-21 03:35:14.994 - lib.adb - ADB: Closing connection - 172.16.5.12
2023-08-20 20:35:14 2023-08-21 03:35:14.995 - server - http disconnect
2023-08-20 20:35:15 2023-08-21 03:35:15.000 - lib.adb - ADB: Connecting to device (attempt 1).
2023-08-20 20:35:15 2023-08-21 03:35:15.013 - root - Tuner: Stream open (attempt 1).
2023-08-20 20:35:15 2023-08-21 03:35:15.072 - lib.adb - ADB: Connected.
2023-08-20 20:35:15 2023-08-21 03:35:15.072 - lib.adb - ADB: Stopping media playback.
2023-08-20 20:35:15 2023-08-21 03:35:15.072 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_MEDIA_STOP
2023-08-20 20:35:15 2023-08-21 03:35:15.083 - httpx - HTTP Request: GET http://172.16.5.53/ts/1_0 "HTTP/1.0 200 Ok"
2023-08-20 20:35:16 2023-08-21 03:35:16.230 - lib.adb - ADB: 172.16.5.12 - input keyevent KEYCODE_MEDIA_PAUSE
2023-08-20 20:35:17 2023-08-21 03:35:17.375 - lib.adb - ADB: Force stopping com.silicondust.view.
2023-08-20 20:35:17 2023-08-21 03:35:17.375 - lib.adb - ADB: 172.16.5.12 - am force-stop com.silicondust.view
2023-08-20 20:35:18 2023-08-21 03:35:18.776 - lib.adb - ADB: Closing connection - 172.16.5.12
2023-08-20 20:35:18 2023-08-21 03:35:18.777 - server - Released tuner 1
2023-08-20 20:35:18 2023-08-21 03:35:18.777 - server - Tuner: Cleanup complete. FireStick (NBC (KPNX))

Thank you for this.

I'm a little bit unsure as to what is happening here.
It is Android 7, which is unsupported and untested, and my guess is that it believed the video was playing when it was actually paused.
But this doesn't explain the restarting application. It should have just displayed the paused video.


These sections here are interesting because the "http disconnect" line indicates that client device (Channels DVR unless you are using something else) disconnected which caused ADBTuner to close the app. Without any additional information the best I can guess is that Channels DVR timed out because ADBTuner took just a little bit too long to return a response.

Regardless, I rolled back to the previous version which does far less and as such won't take as long. Please let me know if things are improved after you update.

If you can, consider upgrading to a Chromecast with Google TV, Fire TV Stick 4K Max, or the Walmart "onn 4K Streaming Box (2023)". These devices are much faster and run newer, better supported versions of Android.

Thanks again for sharing the logs.

I pushed a small change that might help with this. Please update when you have a chance and let me know if you run into this issue again. Thanks!

1 Like

I will check on this later, but I wasn't that concerned about it because I'm waiting for my chromecast to arrive, right now it's just on the firestick.

I saw something today that Fubo is going to release an updated UI.
Its in beta now.....

Oh boy, I hope they keep the URL scheme (plus the activity that can block the who’s watching screen) the same!

It sometimes misses the first digit of the channel for ex .. channel 851 sometimes it only sends 51 ... IT appears to be a timing issue.

Thanks for the followup. I have seen this, I think the "find hdhomerun devices" startup process is sometimes sluggish and that might be playing a role. Device speed is also a factor.

I just pushed an update (08/22) that adds extra startup delay. For Android 12 devices I added a check for the on-screen keyboard to reduce this delay where possible. The Fire TV devices use a non-native keyboard and I wasn't able to find a solution for that (yet).

I also added leading zeros to all single digit channel numbers as single character searches seem to trip up this app (enter button doesn't always work).


CLI version of native on-screen keyboard check (does not work on Fire TV) if it might help anyone in their endeavors.

adb shell dumpsys input_method | grep mServedInputConnectionWrapper | grep com.silicondust.view.ViewUI```

I think mine takes a little longer to startup because I have 5 devices and also the DVR from Silicon Dust.
Will setup and test now.

I see you added a 0 then left(erase) then channel number... seems to be working will keep testing.

The First Channel worked.

The infamous Channel 5 worked ...

I think you have a winner !!!!

I tested Channel Changing while watching livetv with Channels DVR on HDHomeRun tuner and it changed flawlessly.

1 Like

So far so good! Incredible work!

I updated today and tried it, all channels except for the lower tier channels like 3 and 5 change properly. I tried 05 / 5 / 5.0
Actually I believe that the 0 gets populated even when you just put in 5 as your channel. My chromecast still has not arrived, I'm hoping that the chromecast will be the latest android OS and hopefully that is the problem. Thanks for all the effort put into this :slight_smile:

What device are you using I tested all the lower Channels and They all Changed on my Prime using Google Chromecast 1080p... I also have a nic on the Google Chromecast.

I just used 5 ...

Turtle added a 0 then left(erase) then channel number... seems to be working will keep testing.

Hey @turtletank I know that this has come up before, but getting it out here again: what is your intent around this application in terms of making the sources available? I ask because there are one or two enhancements I would like to make - like for example a mechanism to allow additional options to be passed through to your uvicorn server (I run my docker containers behind a treafik proxy which terminates SSL, so without being able to set proxy-headers and forwarded-allow-ips, I see problems with mixed-content warnings and the inability to load static resources like your included js libs, css, etc). I can make the changes I need to make inside a built container, but yeah - you know what happens to those during updates :grinning:.

Honestly I wish you would either just (a) go ahead and pull the trigger on pushing the sources, or (b) be more transparent and open about what you intend to do so that folks can make their own decisions accordingly. If your concern is that you feel like the code is not up to snuff and you want to "clean it up before I publish it" - then that's a classic concern in the open source community and one that is often very misplaced. Your code is fine, we can see it inside the container now anyway if we want to, and anyone who wants to criticize the quality of your code can either (a) go pound sand, or (b) submit a PR with their improvements (put up or shut up as they say). If on the other hand there is some other reason you are stalling on publishing this - well, then at least let us know so that we can decide for ourselves what we want to do. This code and this project is yours, I am certainly not questioning that, it's your decision to make obviously. It just seems like you are not being very forthcoming about it right now.

Thank you very much for your work on this.

@mbcomer68

I'm glad someone finally acknowledged that the source code was not obfuscated in any way :smile: . I never intended for it to be secret and I have been open and willing to share any knowledge I have gained during this project.

It's only been 1.5 months since the original release of ADBTuner. I wanted to add some tests and refactor a bit before an initial open source release and I really just haven't had a good weekend to sit down and get this done. This will happen sooner rather than later, but I think I do have the right to not commit to a specific schedule.

Real life takes priority and this was supposed to be a fun side project!

Thank you for the feedback. I'm sorry you are running into mixed content issues in the web interface. That wasn't a configuration I anticipated anyone using, but it makes sense. I would appreciate your PR once I've gotten things done on my end here.

@mbcomer68
Edit: I just pushed an update to change that config to accept proxy headers from all source IP addresses (proxy_headers=True, forwarded_allow_ips="*"). For what this application is, I'm ok with it being configured this way by default.

3 Likes

Just updated and tested, works fine!

1 Like