Null-DRM-Official/apps/modules/itv/steps.go
404errordeveloper 2e43e6c3fa
All checks were successful
release / build-and-upload (push) Successful in 6m21s
Add ITVX module, transparent mitm_hosts, and DM Telegram announces.
Wire module mitm_hosts into StartTransparent for ITVX capture, ship the
itv provider stub with Live-list autoplay, refresh the README, and send
Forgejo release announces to private chat 7314901602.
2026-10-09 17:35:53 +02:00

153 lines
4.1 KiB
Go

package itv
import (
"fmt"
"regexp"
"strings"
"time"
"drmdecryption/adb"
"drmdecryption/uiflow"
)
// openLiveTab taps bottom-nav Live. Accessibility desc is obfuscated as "Lyve";
// the visible label is still "Live". Prefer the nav item over "Space Live" rows.
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…")
descRE := a.cfg.UI.LiveTabDescRE
if len(descRE) == 0 {
descRE = []string{"^Lyve$"}
}
textRE := a.cfg.UI.LiveTabTextRE
if len(textRE) == 0 {
textRE = []string{"^Live$"}
}
if err := uiflow.TapUI(c, a.CacheDir(), uiflow.Match{
DescRE: descRE,
TextRE: textRE,
Pick: uiflow.PickFirst,
}, time.Duration(a.cfg.Timeouts.LiveNav)); err != nil {
// Fallback: substring match from publish YAML.
if err2 := uiflow.TapUI(c, a.CacheDir(), uiflow.Match{
DescContains: a.cfg.UI.LiveTab,
TextContains: a.cfg.UI.LiveTab,
Pick: uiflow.PickFirst,
}, 8*time.Second); err2 != nil {
return fmt.Errorf("live tab: %w", err)
}
}
time.Sleep(1500 * time.Millisecond)
deadline := time.Now().Add(time.Duration(a.cfg.Timeouts.LiveNav))
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")
}
func (a *App) onLiveTab(nodes []adb.Node) bool {
for _, n := range nodes {
d := strings.ToLower(n.Desc)
if strings.HasPrefix(d, "expand ") && strings.Contains(d, " info button") {
return true
}
if strings.HasPrefix(d, "collapse ") && strings.Contains(d, " info button") {
return true
}
if strings.HasPrefix(d, "watch ") && strings.Contains(d, " on full screen") {
return true
}
}
return false
}
// tapChipThenPlay scrolls the Live channel list for Expand/Collapse {label}
// info button, taps the row, then taps WATCH LIVE / Watch {label} on full screen.
func (a *App) tapChipThenPlay(c *adb.Client, ch Channel) error {
pats := ch.ChipDesc
if len(pats) == 0 {
pats = []string{`(?i)(Expand|Collapse)\s+` + regexp.QuoteMeta(ch.Label) + `\s+info button`}
}
chipRE := uiflow.CompileRes(pats)
fmt.Printf("[*] find Live row for %s…\n", ch.Label)
row, err := a.findChannelRow(c, chipRE)
if err != nil {
return err
}
// Chevron nodes are often not clickable; tap mid-row to the left of the button.
x := 540
if row.X1 > 0 && row.X1 < 400 {
x = row.CX()
}
y := row.CY()
fmt.Printf("[*] tap channel row %q @ %d,%d\n", row.Desc, x, y)
if err := c.Tap(x, y); err != nil {
return err
}
time.Sleep(time.Duration(a.cfg.Timeouts.AfterChannel))
playRE := ch.PlayDesc
if len(playRE) == 0 {
playRE = []string{
`(?i)^WATCH LIVE$`,
`(?i)^Watch\s+` + regexp.QuoteMeta(ch.Label) + `\s+on full screen$`,
}
}
fmt.Println("[*] tap Watch live…")
// Prefer the list "WATCH LIVE" text button for the selected row.
if err := uiflow.TapUI(c, a.CacheDir(), uiflow.Match{
TextRE: playRE,
DescRE: playRE,
Pick: uiflow.PickFirst,
}, time.Duration(a.cfg.Timeouts.WatchLive)); err != nil {
return fmt.Errorf("watch live: %w", err)
}
return nil
}
func (a *App) findChannelRow(c *adb.Client, chipRE []*regexp.Regexp) (*adb.Node, error) {
scrollMax := a.cfg.UI.ChannelScrollMax
if scrollMax <= 0 {
scrollMax = 12
}
// Prefer scrolling down from the top so ITV1/ITV2 are reachable.
_ = c.Swipe(540, 1200, 540, 1900, 250)
time.Sleep(400 * time.Millisecond)
for attempt := 0; attempt <= scrollMax; attempt++ {
nodes, err := c.DumpUI(a.CacheDir())
if err != nil {
return nil, err
}
for i := range nodes {
n := &nodes[i]
if n.Desc == "" {
continue
}
for _, p := range chipRE {
if p.MatchString(n.Desc) {
return n, nil
}
}
}
if attempt == scrollMax {
break
}
fmt.Printf("[*] scroll Live list (%d/%d)…\n", attempt+1, scrollMax)
_ = c.Swipe(540, 1950, 540, 1100, 320)
time.Sleep(700 * time.Millisecond)
}
return nil, fmt.Errorf("channel row not found")
}