AndroidHDMI-for-Channels (ah4c) - FireTV LiveTV capture

@Anvil_DVR

At some point, I'd like to get some feedback from you on error handling in regular use.

Right now after one full pass through guide (which includes two attempts at getting a channel's ID number if missed), the search stops. Similarly, after whatever number you specify in $LIVETV_ATTEMPTS (of steps through the guide) is reached, the search also stops.

I'd like to make these more robust, but strike a balance between how long one is willing to wait when wanting to watch live, versus the desire to have a near-zero failure rate on recordings. I'm leaning towards a second pass through the guide if no matches are found, as this should address occasional situations where there's a miss on the first pass.

I just did a scan and on the second pass, it stops one short from bottom.
I did this after putting the device to sleep.
At the banner, it re-used the last number on the channel following the banner. all the channels after that were off by one and it skipped the last channel.

Could you post the log line that's output when you're sitting on the banner? Maybe it's different from what I've seen.

Its part of the problem, there may be other things going on, I added a channel and it messed up in a couple of spots.

It generally works pretty well. I have seen it go by the channel once or twice. I set the counter to double the number of channels presumably so it will go around twice. Once it picked the wrong channel, but got it right on the next try. It's not speedy, but I don't think there is any way around that. The main issue for me is that I need to manually set the ID for each channel because it's having problems getting those right.

@Anvil_DVR

I messed around with different FireSticks today until I found one that was behaving very similarly to what you've described. I banged my head against it for some time -- trying to figure out what was up, and why it was different. In the end, it was the most obvious of all issues -- it needed a reboot. :crazy_face: I'm also suspicious that responses to logcat queries may get very slow after awhile, or after lots of experimentation -- like we're doing atm.

We'll see where this leads us -- perhaps some sort of scheduled reboot. But, in the meantime, I've improved the resilience of the device-specific M3U creation. If you use the CREATE_M3US=true option, your specified devices will be rebooted before the guide channel scan starts. If you use the ./scripts/firetv/livetv/createm3u.sh your_streaming_device_hostname_or_IP:5555 approach, the device's adb logs will be flushed before scanning begins (no reboot).

It's best to be able to monitor the reboot and M3U creation process to confirm the scan starts, and ends, at the beginning of the guide. If it doesn't, there IS an issue. I had it happen on one test, and it was because of a LiveTV Guide channels (the ones that aren't hidden) to livetv.m3u mismatch.

Also, be sure to check the Portainer-Container log to confirm there are no errors there. Here's an example of a successful container start including M3U creation for two devices:

127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.29.0.2	ah4c2
192.168.110.41 firestick-rack3
192.168.110.162 firestick-rack4
192.168.110.130 encoder_48007
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
connected to firestick-rack3:5555
connected to firestick-rack4:5555
Existing ./scripts/onn/youtubetv/prebmitune.sh found, and will be preserved
Existing ./scripts/firetv/livetv/prebmitune.sh found, and will be preserved
Existing ./scripts/onn/youtubetv/bmitune.sh found, and will be preserved
Existing ./scripts/firetv/livetv/bmitune.sh found, and will be preserved
Existing ./scripts/onn/youtubetv/stopbmitune.sh found, and will be preserved
Existing ./scripts/firetv/livetv/stopbmitune.sh found, and will be preserved
Existing ./scripts/firetv/livetv/createm3u.sh found, and will be preserved
Existing directv.m3u found, and will be preserved
Existing foo-fighters.m3u found, and will be preserved
Existing hulu.m3u found, and will be preserved
Existing youtubetv.m3u found, and will be preserved
Existing sling.m3u found, and will be preserved
Existing fubo.m3u found, and will be preserved
Existing dtvstream.m3u found, and will be preserved
Existing livetv.m3u found, and will be preserved
 Waking firestick-rack3... 
 Sorting livetv.m3u alphabetically to match FireTV LiveTV Guide... 
 Reading firestick-rack3.m3u and updating it with device specific channelID... 
Starting channelID is 3881
assigned to M3U channel name: 24/7 Laughs 
Current channelID is 3491
assigned to M3U channel name: 5StarMAX East 
Current channelID is 3494
assigned to M3U channel name: ActionMAX HD East 
Current channelID is 3491
assigned to M3U channel name: Cinemax HD East 
Current channelID is 3489
assigned to M3U channel name: Cinemax HD West 
Current channelID is 3846
assigned to M3U channel name: Encore Action HD East 
Current channelID is 3849
assigned to M3U channel name: Encore HD East 
Current channelID is 3856
assigned to M3U channel name: HBO 
Current channelID is 3851
assigned to M3U channel name: HBO 2 
Current channelID is 3856
assigned to M3U channel name: HBO Comedy 
Current channelID is 3857
assigned to M3U channel name: HBO Family 
Current channelID is 3852
assigned to M3U channel name: HBO Signature 
Current channelID is 3853
assigned to M3U channel name: HBO West 
Current channelID is 3854
assigned to M3U channel name: HBO Zone 
Current channelID is 3484
assigned to M3U channel name: MGM+ 
Current channelID is 3487
assigned to M3U channel name: MGM+ DRIVE-IN 
Current channelID is 3485
assigned to M3U channel name: MGM+ HITS 
Current channelID is 3486
assigned to M3U channel name: MGM+ MARQUEE 
Current channelID is 3490
assigned to M3U channel name: MoreMAX HD East 
Current channelID is 3493
assigned to M3U channel name: MovieMAX HD East 
Current channelID is 3496
assigned to M3U channel name: OuterMAX HD East 
Current channelID is 3490
assigned to M3U channel name: Showtime 
Current channelID is 3874
assigned to M3U channel name: Showtime West 
Current channelID is 3842
assigned to M3U channel name: Starz Cinema HD East 
Current channelID is 3844
assigned to M3U channel name: Starz Comedy HD East 
Current channelID is 3841
assigned to M3U channel name: Starz Edge HD East 
 EPG ad detected, skipping... 
Current channelID is 3843
assigned to M3U channel name: Starz HD East 
Current channelID is 3845
assigned to M3U channel name: Starz HD West 
Current channelID is 3847
assigned to M3U channel name: Starz inBlack HD East 
Current channelID is 3848
assigned to M3U channel name: Starz Kids AND Family HD East 
Current channelID is 3488
assigned to M3U channel name: ThrillerMAX East 
Current channelID is 3881
 Initial pass through the guide completed 
 Beginning second pass to confirm play/tuner values... 
Confirming a guideID 3881 is present
assigned to M3U channel name: 24/7 Laughs 
Confirming a guideID 3491 is present
assigned to M3U channel name: 5StarMAX East 
Confirming a guideID 3494 is present
assigned to M3U channel name: ActionMAX HD East 
Confirming a guideID 3491 is present
assigned to M3U channel name: Cinemax HD East 
Confirming a guideID 3489 is present
assigned to M3U channel name: Cinemax HD West 
Confirming a guideID 3846 is present
assigned to M3U channel name: Encore Action HD East 
Confirming a guideID 3849 is present
assigned to M3U channel name: Encore HD East 
Confirming a guideID 3856 is present
assigned to M3U channel name: HBO 
Confirming a guideID 3851 is present
assigned to M3U channel name: HBO 2 
Confirming a guideID 3856 is present
assigned to M3U channel name: HBO Comedy 
Confirming a guideID 3857 is present
assigned to M3U channel name: HBO Family 
Confirming a guideID 3852 is present
assigned to M3U channel name: HBO Signature 
Confirming a guideID 3853 is present
assigned to M3U channel name: HBO West 
Confirming a guideID 3854 is present
assigned to M3U channel name: HBO Zone 
Confirming a guideID 3484 is present
assigned to M3U channel name: MGM+ 
Confirming a guideID 3487 is present
assigned to M3U channel name: MGM+ DRIVE-IN 
Confirming a guideID 3485 is present
assigned to M3U channel name: MGM+ HITS 
Confirming a guideID 3486 is present
assigned to M3U channel name: MGM+ MARQUEE 
Confirming a guideID 3490 is present
assigned to M3U channel name: MoreMAX HD East 
Confirming a guideID 3493 is present
assigned to M3U channel name: MovieMAX HD East 
Confirming a guideID 3496 is present
assigned to M3U channel name: OuterMAX HD East 
Confirming a guideID 3490 is present
assigned to M3U channel name: Showtime 
Confirming a guideID 3874 is present
assigned to M3U channel name: Showtime West 
Confirming a guideID 3842 is present
assigned to M3U channel name: Starz Cinema HD East 
Confirming a guideID 3844 is present
assigned to M3U channel name: Starz Comedy HD East 
Confirming a guideID 3841 is present
assigned to M3U channel name: Starz Edge HD East 
Confirming a guideID 3843 is present
assigned to M3U channel name: Starz HD East 
Confirming a guideID 3845 is present
assigned to M3U channel name: Starz HD West 
Confirming a guideID 3847 is present
assigned to M3U channel name: Starz inBlack HD East 
Confirming a guideID 3848 is present
assigned to M3U channel name: Starz Kids AND Family HD East 
Confirming a guideID 3488 is present
assigned to M3U channel name: ThrillerMAX East 
 Device specific M3U creation appears successful as the starting and ending channel IDs match. 
 It's recommended NOT to leave CREATE_M3US set to true. Create new device specific M3Us only as needed. 
 Final format of new firestick-rack3.m3u... 
 Waking firestick-rack4... 
 Sorting livetv.m3u alphabetically to match FireTV LiveTV Guide... 
 Reading firestick-rack4.m3u and updating it with device specific channelID... 
Starting channelID is 3658
assigned to M3U channel name: 24/7 Laughs 
Current channelID is 2404
assigned to M3U channel name: 5StarMAX East 
Current channelID is 2407
assigned to M3U channel name: ActionMAX HD East 
Current channelID is 2405
assigned to M3U channel name: Cinemax HD East 
Current channelID is 2402
assigned to M3U channel name: Cinemax HD West 
Current channelID is 3205
assigned to M3U channel name: Encore Action HD East 
Current channelID is 3208
assigned to M3U channel name: Encore HD East 
Current channelID is 3635
assigned to M3U channel name: HBO 
Current channelID is 3630
assigned to M3U channel name: HBO 2 
Current channelID is 3634
assigned to M3U channel name: HBO Comedy 
Current channelID is 3636
assigned to M3U channel name: HBO Family 
Current channelID is 3631
assigned to M3U channel name: HBO Signature 
Current channelID is 3632
assigned to M3U channel name: HBO West 
Current channelID is 3633
assigned to M3U channel name: HBO Zone 
Current channelID is 2399
assigned to M3U channel name: MGM+ 
Current channelID is 2398
assigned to M3U channel name: MGM+ DRIVE-IN 
Current channelID is 2400
assigned to M3U channel name: MGM+ HITS 
Current channelID is 2397
assigned to M3U channel name: MGM+ MARQUEE 
Current channelID is 2403
assigned to M3U channel name: MoreMAX HD East 
Current channelID is 2406
assigned to M3U channel name: MovieMAX HD East 
Current channelID is 2409
assigned to M3U channel name: OuterMAX HD East 
Current channelID is 3656
assigned to M3U channel name: Showtime 
Current channelID is 3651
assigned to M3U channel name: Showtime West 
Current channelID is 3201
assigned to M3U channel name: Starz Cinema HD East 
Current channelID is 3203
assigned to M3U channel name: Starz Comedy HD East 
Current channelID is 3209
assigned to M3U channel name: Starz Edge HD East 
Current channelID is 3202
assigned to M3U channel name: Starz HD East 
Current channelID is 3204
assigned to M3U channel name: Starz HD West 
Current channelID is 3206
assigned to M3U channel name: Starz inBlack HD East 
Current channelID is 3207
assigned to M3U channel name: Starz Kids AND Family HD East 
Current channelID is 2401
assigned to M3U channel name: ThrillerMAX East 
Current channelID is 3658
 Initial pass through the guide completed 
 Beginning second pass to confirm play/tuner values... 
Confirming a guideID 3658 is present
assigned to M3U channel name: 24/7 Laughs 
Confirming a guideID 2404 is present
assigned to M3U channel name: 5StarMAX East 
Confirming a guideID 2407 is present
assigned to M3U channel name: ActionMAX HD East 
Confirming a guideID 2405 is present
assigned to M3U channel name: Cinemax HD East 
Confirming a guideID 2402 is present
assigned to M3U channel name: Cinemax HD West 
Confirming a guideID 3205 is present
assigned to M3U channel name: Encore Action HD East 
Confirming a guideID 3208 is present
assigned to M3U channel name: Encore HD East 
Confirming a guideID 3635 is present
assigned to M3U channel name: HBO 
Confirming a guideID 3630 is present
assigned to M3U channel name: HBO 2 
Confirming a guideID 3634 is present
assigned to M3U channel name: HBO Comedy 
Confirming a guideID 3636 is present
assigned to M3U channel name: HBO Family 
Confirming a guideID 3631 is present
assigned to M3U channel name: HBO Signature 
Confirming a guideID 3632 is present
assigned to M3U channel name: HBO West 
Confirming a guideID 3633 is present
assigned to M3U channel name: HBO Zone 
Confirming a guideID 2399 is present
assigned to M3U channel name: MGM+ 
Confirming a guideID 2398 is present
assigned to M3U channel name: MGM+ DRIVE-IN 
Confirming a guideID 2400 is present
assigned to M3U channel name: MGM+ HITS 
Confirming a guideID 2397 is present
assigned to M3U channel name: MGM+ MARQUEE 
Confirming a guideID 2403 is present
assigned to M3U channel name: MoreMAX HD East 
Confirming a guideID 2406 is present
assigned to M3U channel name: MovieMAX HD East 
Confirming a guideID 2409 is present
assigned to M3U channel name: OuterMAX HD East 
Confirming a guideID 3656 is present
assigned to M3U channel name: Showtime 
Confirming a guideID 3651 is present
assigned to M3U channel name: Showtime West 
Confirming a guideID 3201 is present
assigned to M3U channel name: Starz Cinema HD East 
Confirming a guideID 3203 is present
assigned to M3U channel name: Starz Comedy HD East 
Confirming a guideID 3209 is present
assigned to M3U channel name: Starz Edge HD East 
Confirming a guideID 3202 is present
assigned to M3U channel name: Starz HD East 
Confirming a guideID 3204 is present
assigned to M3U channel name: Starz HD West 
Confirming a guideID 3206 is present
assigned to M3U channel name: Starz inBlack HD East 
Confirming a guideID 3207 is present
assigned to M3U channel name: Starz Kids AND Family HD East 
Confirming a guideID 2401 is present
assigned to M3U channel name: ThrillerMAX East 
 Device specific M3U creation appears successful as the starting and ending channel IDs match. 
 It's recommended NOT to leave CREATE_M3US set to true. Create new device specific M3Us only as needed. 
 Final format of new firestick-rack4.m3u... 
[START] androidhdmi-for-channels is starting
[ENV] Not loading env
[ENV] IPADDRESS                  htpc6:7664
[ENV] ALERT_SMTP_SERVER          
[ENV] ALERT_AUTH_SERVER          
[ENV] ALERT_EMAIL_FROM           
[ENV] ALERT_EMAIL_PASS           
[ENV] ALERT_EMAIL_TO             
[ENV] ALERT_WEBHOOK_URL          
[ENV] ALLOW_DEBUG_VIDEO_PREVIEW  
[ENV] Creating tuner             1
[ENV] ENCODER1_URL               http://encoder_48007/8.ts
[ENV] TUNER1_IP                  firestick-rack3:5555
[ENV] CMD1                       
[ENV] TEECMD1                    
[ENV] PRE SCRIPT                 ./scripts/firetv/livetv/prebmitune.sh
[ENV] START SCRIPT               ./scripts/firetv/livetv/bmitune.sh
[ENV] STOP SCRIPT                ./scripts/firetv/livetv/stopbmitune.sh
[ENV] REBOOT SCRIPT              ./scripts/firetv/livetv/reboot.sh
[ENV] Creating tuner             2
[ENV] ENCODER2_URL               http://encoder_48007/12.ts
[ENV] TUNER2_IP                  firestick-rack4:5555
[ENV] CMD2                       
[ENV] TEECMD2                    
[ENV] PRE SCRIPT                 ./scripts/firetv/livetv/prebmitune.sh
[ENV] START SCRIPT               ./scripts/firetv/livetv/bmitune.sh
[ENV] STOP SCRIPT                ./scripts/firetv/livetv/stopbmitune.sh
[ENV] REBOOT SCRIPT              ./scripts/firetv/livetv/reboot.sh
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET    /favicon.ico              --> github.com/gin-gonic/gin.(*RouterGroup).StaticFile.func1 (2 handlers)
[GIN-debug] HEAD   /favicon.ico              --> github.com/gin-gonic/gin.(*RouterGroup).StaticFile.func1 (2 handlers)
[GIN-debug] Loaded HTML Templates (11): 
      
	- m3us.html
	- routes.html
	- status.html
	- stream.html
	- config.html
	- index.html
      
	- logs.html
	- status_and_logs.html
	- 
      
	- edit.html
	- editm3u.html
[GIN-debug] GET    /static/*filepath         --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (2 handlers)
[GIN-debug] HEAD   /static/*filepath         --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (2 handlers)
[GIN-debug] GET    /                         --> main.run.func1 (2 handlers)
[GIN-debug] GET    /routes                   --> main.run.func2 (2 handlers)
[GIN-debug] GET    /play/tuner:tuner/:channel --> main.run.func3 (2 handlers)
[GIN-debug] GET    /m3u/:channel             --> main.run.func4 (2 handlers)
[GIN-debug] GET    /env                      --> main.run.func5 (2 handlers)
[GIN-debug] GET    /logs/text                --> main.run.func6 (2 handlers)
[GIN-debug] GET    /logs                     --> main.run.func7 (2 handlers)
[GIN-debug] GET    /status/andlogs           --> main.run.func8 (2 handlers)
[GIN-debug] GET    /logs/json                --> main.run.func9 (2 handlers)
[GIN-debug] GET    /video                    --> main.run.func10 (2 handlers)
[GIN-debug] GET    /status                   --> main.statusPageHandler (2 handlers)
[GIN-debug] GET    /api/status               --> main.apiStatusHandler (2 handlers)
[GIN-debug] GET    /stream                   --> main.run.func11 (2 handlers)
[GIN-debug] GET    /test/webhook             --> main.run.func12 (2 handlers)
[GIN-debug] GET    /test/email               --> main.run.func13 (2 handlers)
[GIN-debug] GET    /status/channelsactivity  --> main.run.func14 (2 handlers)
[GIN-debug] GET    /edit                     --> main.run.func15 (2 handlers)
[GIN-debug] POST   /save                     --> main.run.func16 (2 handlers)
[GIN-debug] POST   /m3usave/:file            --> main.run.func17 (2 handlers)
[GIN-debug] GET    /m3us                     --> main.run.func18 (2 handlers)
[GIN-debug] GET    /editm3u/:file            --> main.run.func19 (2 handlers)
[GIN-debug] GET    /config                   --> main.run.func20 (2 handlers)
[GIN-debug] POST   /configsave               --> main.run.func21 (2 handlers)
[START] androidhdmi-for-channels is ready
[GIN-debug] Listening and serving HTTP on :7654
> ws-scrcpy@0.8.1-dev start
> node ./index.js
Listening on:
	http://ah4c2:8000 http://localhost:8000
	http://127.0.0.1:8000 http://172.29.0.2:8000

Go ahead and re-pull and redeploy the bnhf/ah4c:prime image with UPDATE_SCRIPTS=true, and this will reboot your device and reinitiate a scan. Let me know how it goes.

It worked!
Now I'm gonna working on getting a second FireTV going.

Awesome work here!

Edit: Have it working with 2 FireTV Sticks.
Oddly the first one still is showing a banner in the guide, the one I just added does not.
Once in a while when hunting for the channel, it will go past the banner, then backup to the banner and then go forward again. Once I saw it back up to the banner and just sit there.

Everything re-scanned perfectly for both FireTV's, so that part seems to be fixed.

I'm glad to hear the M3U creation portion is holding. I'll shift my attention to adding more error handling to the tuning portion next. I'd like to include "Thursday Night Football" to the scheme as well, and ultimately combine this with what I've done with DirecTV, so one set of v-tuners can handle all.

Thanks for keeping me in-the-loop on results from your end.

My pleasure.

I just saw it move a couple of channels and then just stop searching. Maybe it's just something with the device though. Usually works ok.
I'll be in the market for a new streaming service. I've given up on Hulu. They have a fetish with authentication that is annoying. Perhaps DirecTV Stream.

Today's build has what I hope are a couple of improvements, both in logic and error handling:

  • Searching through the guide will no longer terminate when the current guide channel is the same as the starting guide channel. Searching will only terminate after the number of attempts specified in LIVETV_ATTEMPTS. Never set this lower than about 2/3 of the number of channels you have -- up to about a 2x maximum.

  • Since starting from the top of the guide is crucial, I've added a better function to confirm that -- with a maximum of 5 attempts, after which we'll just have to assume we're there. You'll see a move to the bottom of the guide, followed by a move all the way to the top again, attempting to get the guide ID. Usually no more than 1 retry max should be required.

  • One bit that's unchanged, is that for any channel ID's that are missed when stepping through the guide, there will be one attempt to read it again. This means moving down one channel, and then up again in the guide for a second try at getting the ID. I'll probably make this an environment variable at some point, as those who mostly record are going to care more about certainty than speed.

Now that you have your device-specific M3Us built, I'd suggest setting CREATE_M3US=false, unless you've changed livetv.m3u and want new ones created. Also, be sure you have UPDATE_SCRIPTS=true to get the changes outlined above.

I will test this tonight.
Thanks

Edit: So far so good. No issues.
One place that could be optimized is when the target channel is right after a banner.
Oddly this seems to happen more than you would think.
Not a big deal though...
Amazon likes to add channels that then need to be hidden. This does not break anything though.
Thumbs Up!

Edit 2: I have noticed it do a recheck a few times while doing the channel search.
It obviously does this when it hits a banner, but I have seen it do it at normal channel positions.
So your logic seems appropriate and is working well.

Found a problem related to channels with names that start with numbers. Should be fixed now -- re-pull and redeploy when you have a chance. Affects those v-tuning Prime Video Channels only. New bnhf/ah4c:prime pushed a few minutes ago.

Got it.
Working great this far.

I noticed that you can add DirecTV channels to the live TV menu on the fire TV. Not sure if this is preferred way to do it, but it looks like if you needed a few channels from DirecTV stream this would work.

I've read that's possible, but only if you have DTVStream credentials, not DTVSat like me.

I'm planning to combine what we've done with DTV and Prime Premium into one set of scripts, as that should be the best for all combos.

Just not sure on the timing, as I'm headed to Portugal shortly for the first half of the Winter and AZ for the second.

I'll likely get to it sooner rather than later though, but in the meantime the LiveTV option might be good. You can also run two ah4c containers, one for Prime and one for DTV -- two tuners each. That's what I'm doing atm.

2 Likes

I'm having surgery in a few days so I will have some time to mess around with this while I recover.

If I run a second container for DTVStream, does that require FireTV? Or will it work with Chromecast?

It should work with Chromecast -- untested though.

1 Like

I have a question about the Prime Tuner.
Is there a particular procedure I should be doing anytime I need to restart the PC or Docker Engine in Windows?
What's happening is I need to edit the channel m3u and re-create the device m3u's, and re-allow ADB-USB debugging an the FireTV's anytime there is a docker update, or I restart the system.

That shouldn't be happening. These lines in the docker-compose map scripts, m3u and adb device data to persistent directories on your Docker host:

 volumes:
      - /data/ah4c/scripts:/opt/scripts # pre/stop/bmitune.sh scripts will be stored in this bound host directory under streamer/app
      - /data/ah4c/m3u:/opt/m3u # m3u files will be stored here and hosted at http://<hostname or ip>:7654/m3u for use in Channels DVR - Custom Channels settings
      - /data/ah4c/adb:/root/.android # Persistent data directory for adb keys

You can change the /data/ part to suit (i.e use a different parent), but the rest (from ah4c on) should all be as shown. Is that what you have in Portainer-Stacks?