- streamd: MPD-only start, proxy field, ffmpeg/NRE/mp4decrypt auto-install - GET/PUT /api/modules for module.yaml sync; agent sync_modules - RTE Live-tab AutoPlay fixes; modules zip named bbc/rte/tg4.zip - Telegram notify scripts wired into Forgejo release workflows
134 lines
4 KiB
Go
134 lines
4 KiB
Go
package rte
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"time"
|
|
|
|
"drmdecryption/adb"
|
|
"drmdecryption/uiflow"
|
|
)
|
|
|
|
// openLiveTab taps the bottom-nav Live tab and waits for channel chips.
|
|
// Home also shows a "Watch Live" label and a "Live Event" row — those must not
|
|
// match. The real control's content-desc is "Live tab, N out of 5".
|
|
func (a *App) openLiveTab(c *adb.Client) error {
|
|
c.DismissShadeIfFocused()
|
|
if nodes, err := c.DumpUI(a.CacheDir()); err == nil && a.onLiveTab(nodes) {
|
|
fmt.Println("[*] already on Live tab")
|
|
return nil
|
|
}
|
|
|
|
fmt.Println("[*] open Live tab…")
|
|
if err := uiflow.TapUI(c, a.CacheDir(), uiflow.Match{
|
|
DescRE: a.cfg.UI.LiveTabDescRE,
|
|
Pick: uiflow.PickSmallest,
|
|
}, time.Duration(a.cfg.Timeouts.LiveTab)); err != nil {
|
|
return fmt.Errorf("live tab: %w", err)
|
|
}
|
|
time.Sleep(time.Duration(a.cfg.Timeouts.AfterLiveTab))
|
|
|
|
deadline := time.Now().Add(time.Duration(a.cfg.Timeouts.LiveTab))
|
|
for time.Now().Before(deadline) {
|
|
nodes, err := c.DumpUI(a.CacheDir())
|
|
if err == nil && a.onLiveTab(nodes) {
|
|
fmt.Println("[*] Live tab ready")
|
|
return nil
|
|
}
|
|
time.Sleep(700 * time.Millisecond)
|
|
}
|
|
return fmt.Errorf("Live tab did not open")
|
|
}
|
|
|
|
// onLiveTab is true when channel chips are on screen. Home often embeds the
|
|
// same chip rail, so this also short-circuits when Play is already reachable
|
|
// without tapping the bottom-nav Live tab.
|
|
func (a *App) onLiveTab(nodes []adb.Node) bool {
|
|
return a.chipCount(nodes) >= 1
|
|
}
|
|
|
|
func (a *App) chipCount(nodes []adb.Node) int {
|
|
n := 0
|
|
for _, ch := range a.cfg.Channels {
|
|
pats := uiflow.CompileRes(ch.ChipDesc)
|
|
if adb.FindSmallest(nodes, pats) != nil {
|
|
n++
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
// tapChipThenPlay is this app's navigation idiom: on the Live tab, tap the
|
|
// channel chip, then the large hero Play button that appears. If the hero button
|
|
// is already on screen for this channel, tap it directly.
|
|
func (a *App) tapChipThenPlay(c *adb.Client, ch Channel) error {
|
|
playPats := uiflow.CompileRes(ch.PlayDesc)
|
|
chipPats := uiflow.CompileRes(ch.ChipDesc)
|
|
|
|
nodes, err := c.DumpUI(a.CacheDir())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if cand := a.findHeroPlay(nodes, playPats); cand != nil {
|
|
x, y := playTapXY(cand)
|
|
fmt.Printf("[*] tap Play %q @ %d,%d\n", cand.Desc, x, y)
|
|
return c.Tap(x, y)
|
|
}
|
|
|
|
chip := adb.FindSmallest(nodes, chipPats)
|
|
if chip == nil {
|
|
deadline := time.Now().Add(time.Duration(a.cfg.Timeouts.ChipWait))
|
|
for time.Now().Before(deadline) {
|
|
nodes, err = c.DumpUI(a.CacheDir())
|
|
if err == nil {
|
|
if chip = adb.FindSmallest(nodes, chipPats); chip != nil {
|
|
break
|
|
}
|
|
}
|
|
time.Sleep(700 * time.Millisecond)
|
|
}
|
|
if chip == nil {
|
|
return fmt.Errorf("chip not found for %s", ch.Label)
|
|
}
|
|
}
|
|
// Chip text nodes are often clickable=false; their centre sits inside a
|
|
// larger clickable parent, so a centre tap still lands on the parent.
|
|
fmt.Printf("[*] tap chip %q @ %d,%d\n", chip.Desc, chip.CX(), chip.CY())
|
|
_ = c.Tap(chip.CX(), chip.CY())
|
|
time.Sleep(time.Duration(a.cfg.Timeouts.AfterChip))
|
|
|
|
deadline := time.Now().Add(time.Duration(a.cfg.Timeouts.PlayWait))
|
|
for time.Now().Before(deadline) {
|
|
nodes, err = c.DumpUI(a.CacheDir())
|
|
if err == nil {
|
|
if cand := a.findHeroPlay(nodes, playPats); cand != nil {
|
|
x, y := playTapXY(cand)
|
|
fmt.Printf("[*] tap Play %q @ %d,%d\n", cand.Desc, x, y)
|
|
return c.Tap(x, y)
|
|
}
|
|
}
|
|
time.Sleep(700 * time.Millisecond)
|
|
}
|
|
return fmt.Errorf("Play button did not appear for %s", ch.Label)
|
|
}
|
|
|
|
// findHeroPlay accepts a Play match only if it is big enough to be the hero
|
|
// button rather than a small list-item play icon.
|
|
func (a *App) findHeroPlay(nodes []adb.Node, playPats []*regexp.Regexp) *adb.Node {
|
|
cand := adb.FindLargest(nodes, nil, playPats)
|
|
if cand == nil || cand.Area() < a.cfg.HeroMinArea {
|
|
return nil
|
|
}
|
|
return cand
|
|
}
|
|
|
|
// playTapXY aims at the play icon in the upper half of the hero. The geometric
|
|
// centre of the large "Play RTEONE…" node often lands below the hit target and
|
|
// the tap is ignored.
|
|
func playTapXY(n *adb.Node) (int, int) {
|
|
h := n.Y2 - n.Y1
|
|
if h < 1 {
|
|
return n.CX(), n.CY()
|
|
}
|
|
return n.CX(), n.Y1 + h*2/5
|
|
}
|