All checks were successful
release / build-and-upload (push) Successful in 7m5s
- Rename product/host binary to streamd (drm compat copy still shipped) - Go module path streamd; STREAMD_* env aliases; agent UA streamd-agent - Panel Modules store + agent pull sync (modstore / modsync) - Rolling stable + beta download tags; README/docs channel curl blocks - Release notes in docs/releases/v0.2.0.md attached by Forgejo Actions
175 lines
4.3 KiB
Go
175 lines
4.3 KiB
Go
package c4
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
|
|
"streamd/adb"
|
|
"streamd/uiflow"
|
|
)
|
|
|
|
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 TV")
|
|
return nil
|
|
}
|
|
|
|
fmt.Println("[*] open Live TV…")
|
|
descRE := a.cfg.UI.LiveTabDescRE
|
|
if len(descRE) == 0 {
|
|
descRE = []string{`(?i)^Live TV$`}
|
|
}
|
|
textRE := a.cfg.UI.LiveTabTextRE
|
|
if len(textRE) == 0 {
|
|
textRE = []string{`(?i)^Live TV$`}
|
|
}
|
|
if err := uiflow.TapUI(c, a.CacheDir(), uiflow.Match{
|
|
DescRE: descRE,
|
|
TextRE: textRE,
|
|
DescContains: a.cfg.UI.LiveTab,
|
|
TextContains: a.cfg.UI.LiveTab,
|
|
Pick: uiflow.PickFirst,
|
|
}, time.Duration(a.cfg.Timeouts.LiveNav)); err != 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 TV ready")
|
|
a.disableLiveAutoPlay(c)
|
|
return nil
|
|
}
|
|
time.Sleep(700 * time.Millisecond)
|
|
}
|
|
return fmt.Errorf("Live TV did not open")
|
|
}
|
|
|
|
// disableLiveAutoPlay turns off the Live TV "Auto-play" toggle so the app does
|
|
// not advance to the next channel while we wait for MITM.
|
|
func (a *App) disableLiveAutoPlay(c *adb.Client) {
|
|
nodes, err := c.DumpUI(a.CacheDir())
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, n := range nodes {
|
|
d := strings.ToLower(strings.TrimSpace(n.Desc))
|
|
t := strings.ToLower(strings.TrimSpace(n.Text))
|
|
if d != "auto-play" && t != "auto-play" {
|
|
continue
|
|
}
|
|
if n.Selected || n.Checked {
|
|
fmt.Println("[*] disable Live Auto-play")
|
|
_ = c.Tap(n.CX(), n.CY())
|
|
time.Sleep(500 * time.Millisecond)
|
|
return
|
|
}
|
|
// State may not be exposed — leave alone when already off / unknown.
|
|
fmt.Println("[*] Live Auto-play control present (left as-is)")
|
|
return
|
|
}
|
|
}
|
|
|
|
func (a *App) onLiveTab(nodes []adb.Node) bool {
|
|
for _, n := range nodes {
|
|
d := strings.ToLower(n.Desc)
|
|
if strings.Contains(d, "select to watch") {
|
|
return true
|
|
}
|
|
if strings.Contains(d, "now showing on") {
|
|
return true
|
|
}
|
|
if strings.EqualFold(n.Desc, "Live TV, heading") || strings.EqualFold(n.Text, "On now") {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// tapChannelCard scrolls the Live list for "Select to watch {Label}" and taps it.
|
|
func (a *App) tapChannelCard(c *adb.Client, ch Channel) error {
|
|
pats := ch.ChipDesc
|
|
if len(pats) == 0 {
|
|
pats = []string{`(?i)Select to watch\s+` + regexp.QuoteMeta(ch.Label)}
|
|
}
|
|
chipRE := uiflow.CompileRes(pats)
|
|
fmt.Printf("[*] find Live card for %s…\n", ch.Label)
|
|
|
|
row, err := a.findChannelCard(c, chipRE)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Printf("[*] tap %q @ %d,%d\n", trimDesc(row.Desc, 60), row.CX(), row.CY())
|
|
if err := c.Tap(row.CX(), row.CY()); err != nil {
|
|
return err
|
|
}
|
|
time.Sleep(time.Duration(a.cfg.Timeouts.AfterChannel))
|
|
return nil
|
|
}
|
|
|
|
func (a *App) findChannelCard(c *adb.Client, chipRE []*regexp.Regexp) (*adb.Node, error) {
|
|
scrollMax := a.cfg.UI.ChannelScrollMax
|
|
if scrollMax <= 0 {
|
|
scrollMax = 10
|
|
}
|
|
// Prefer starting near the top so Channel Four / E4 are reachable.
|
|
_ = c.Swipe(540, 1100, 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
|
|
}
|
|
var best *adb.Node
|
|
for i := range nodes {
|
|
n := &nodes[i]
|
|
hay := n.Desc
|
|
if hay == "" {
|
|
hay = n.Text
|
|
}
|
|
if hay == "" {
|
|
continue
|
|
}
|
|
// Skip cards clipped into the bottom nav (false taps).
|
|
if n.Y2 > 2100 || n.CY() > 2050 {
|
|
continue
|
|
}
|
|
for _, p := range chipRE {
|
|
if !p.MatchString(hay) {
|
|
continue
|
|
}
|
|
// Prefer the explicit "Select to watch" control when present.
|
|
if strings.Contains(strings.ToLower(hay), "select to watch") {
|
|
return n, nil
|
|
}
|
|
if best == nil {
|
|
best = n
|
|
}
|
|
}
|
|
}
|
|
if best != nil {
|
|
return best, nil
|
|
}
|
|
if attempt == scrollMax {
|
|
break
|
|
}
|
|
fmt.Printf("[*] scroll Live list (%d/%d)…\n", attempt+1, scrollMax)
|
|
_ = c.Swipe(540, 1950, 540, 900, 320)
|
|
time.Sleep(700 * time.Millisecond)
|
|
}
|
|
return nil, fmt.Errorf("channel card not found")
|
|
}
|
|
|
|
func trimDesc(s string, n int) string {
|
|
s = strings.TrimSpace(s)
|
|
if len(s) <= n {
|
|
return s
|
|
}
|
|
return s[:n] + "…"
|
|
}
|