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
265 lines
6.5 KiB
Go
265 lines
6.5 KiB
Go
package my5
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
"time"
|
|
|
|
"streamd/adb"
|
|
"streamd/uiflow"
|
|
)
|
|
|
|
func (a *App) appFocused(c *adb.Client) bool {
|
|
out, err := c.Shell("dumpsys", "window")
|
|
if err != nil {
|
|
return false
|
|
}
|
|
pkg := a.Package()
|
|
for _, line := range strings.Split(out, "\n") {
|
|
if strings.Contains(line, "mCurrentFocus") && strings.Contains(line, pkg) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (a *App) dismissOnboarding(c *adb.Client) {
|
|
deadline := time.Now().Add(8 * time.Second)
|
|
for time.Now().Before(deadline) {
|
|
nodes, err := c.DumpUI(a.CacheDir())
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, n := range nodes {
|
|
t := strings.TrimSpace(n.Text)
|
|
switch {
|
|
case strings.EqualFold(t, "Not now"),
|
|
strings.EqualFold(t, "Just browse"),
|
|
strings.EqualFold(t, "Skip register"):
|
|
fmt.Printf("[*] dismiss %q\n", t)
|
|
_ = c.Tap(n.CX(), n.CY())
|
|
time.Sleep(800 * time.Millisecond)
|
|
goto next
|
|
}
|
|
}
|
|
return
|
|
next:
|
|
}
|
|
}
|
|
|
|
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")
|
|
return nil
|
|
}
|
|
time.Sleep(700 * time.Millisecond)
|
|
}
|
|
return fmt.Errorf("Live TV did not open")
|
|
}
|
|
|
|
func (a *App) onLiveTab(nodes []adb.Node) bool {
|
|
for _, n := range nodes {
|
|
id := strings.ToLower(n.ResourceID)
|
|
if strings.Contains(id, "tv_guide_channel_logos") ||
|
|
strings.Contains(id, "tv_guide_epg") ||
|
|
strings.Contains(id, "tv_guide_player") ||
|
|
strings.Contains(id, "tv_guide_navigation") && n.Selected {
|
|
return true
|
|
}
|
|
if strings.EqualFold(n.Text, "Now") && strings.Contains(id, "tv_guide_header_now") {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (a *App) logoNodes(nodes []adb.Node) []adb.Node {
|
|
maxX := a.cfg.UI.LogoMaxX
|
|
minY := a.cfg.UI.LogoMinY
|
|
maxY := a.cfg.UI.LogoMaxY
|
|
var out []adb.Node
|
|
for _, n := range nodes {
|
|
if !strings.Contains(n.Class, "ImageView") {
|
|
continue
|
|
}
|
|
// Channel logos in the Live rail have empty resource-id; EPG thumbs do not.
|
|
if strings.TrimSpace(n.ResourceID) != "" {
|
|
continue
|
|
}
|
|
if n.X1 >= maxX || n.Y1 < minY || n.Y1 >= maxY {
|
|
continue
|
|
}
|
|
// Skip tiny icons / nav glyphs.
|
|
if (n.Y2-n.Y1) < 120 || (n.X2-n.X1) < 120 {
|
|
continue
|
|
}
|
|
if !n.Clickable {
|
|
continue
|
|
}
|
|
out = append(out, n)
|
|
}
|
|
sort.Slice(out, func(i, j int) bool {
|
|
if out[i].Y1 == out[j].Y1 {
|
|
return out[i].X1 < out[j].X1
|
|
}
|
|
return out[i].Y1 < out[j].Y1
|
|
})
|
|
return out
|
|
}
|
|
|
|
// tapChannelLogo scrolls the left logo rail from the top by logo_index rows, then taps.
|
|
func (a *App) tapChannelLogo(c *adb.Client, ch Channel) error {
|
|
want := ch.LogoIndex
|
|
if want < 0 {
|
|
return fmt.Errorf("logo_index must be >= 0")
|
|
}
|
|
fmt.Printf("[*] find logo index %d (%s)…\n", want, ch.Label)
|
|
|
|
// Scroll to the top of the logo rail.
|
|
for i := 0; i < 8; i++ {
|
|
_ = c.Swipe(118, 1000, 118, 1950, 250)
|
|
time.Sleep(280 * time.Millisecond)
|
|
}
|
|
time.Sleep(400 * time.Millisecond)
|
|
|
|
nodes, err := c.DumpUI(a.CacheDir())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
logos := a.logoNodes(nodes)
|
|
if len(logos) == 0 {
|
|
return fmt.Errorf("no channel logos visible")
|
|
}
|
|
rowH := logos[0].Y2 - logos[0].Y1
|
|
if rowH < 120 {
|
|
rowH = 205
|
|
}
|
|
// Gap between rows is small; step ≈ row height + ~10px from observed layout.
|
|
step := rowH + 10
|
|
|
|
// Bring target near the top by single-row swipes, then tap it in-view.
|
|
for i := 0; i < want; i++ {
|
|
_ = c.Swipe(118, 1200, 118, 1200-step, 220)
|
|
time.Sleep(350 * time.Millisecond)
|
|
}
|
|
time.Sleep(400 * time.Millisecond)
|
|
|
|
nodes, err = c.DumpUI(a.CacheDir())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
logos = a.logoNodes(nodes)
|
|
if len(logos) == 0 {
|
|
return fmt.Errorf("no channel logos after scroll to index %d", want)
|
|
}
|
|
|
|
var n adb.Node
|
|
if want == 0 {
|
|
n = logos[0]
|
|
} else {
|
|
// After want single-row swipes from top, the target is the first fully
|
|
// visible logo (previous rows scrolled off). Prefer logos[0] when fully
|
|
// on-screen; otherwise logos[1] if the top one is clipped.
|
|
n = logos[0]
|
|
if n.Y1 < a.cfg.UI.LogoMinY+5 && len(logos) > 1 {
|
|
n = logos[1]
|
|
}
|
|
}
|
|
if n.CY() >= 2050 || n.Y2 > a.cfg.UI.LogoMaxY {
|
|
return fmt.Errorf("logo index %d clipped into nav", want)
|
|
}
|
|
fmt.Printf("[*] tap logo %d @ %d,%d\n", want, n.CX(), n.CY())
|
|
if err := c.Tap(n.CX(), n.CY()); err != nil {
|
|
return err
|
|
}
|
|
time.Sleep(time.Duration(a.cfg.Timeouts.AfterChannel))
|
|
return nil
|
|
}
|
|
|
|
func abs(v int) int {
|
|
if v < 0 {
|
|
return -v
|
|
}
|
|
return v
|
|
}
|
|
|
|
// tapNowCell taps the "Now" EPG cell aligned with the selected logo row.
|
|
// After tapChannelLogo scrolls the target to the top of the rail, align to logos[0].
|
|
func (a *App) tapNowCell(c *adb.Client, ch Channel) error {
|
|
_ = ch
|
|
nodes, err := c.DumpUI(a.CacheDir())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
logos := a.logoNodes(nodes)
|
|
if len(logos) == 0 {
|
|
return fmt.Errorf("no logos after select")
|
|
}
|
|
logo := &logos[0]
|
|
if logo.Y1 < a.cfg.UI.LogoMinY+5 && len(logos) > 1 {
|
|
logo = &logos[1]
|
|
}
|
|
|
|
var best *adb.Node
|
|
bestDist := 1 << 30
|
|
for i := range nodes {
|
|
n := &nodes[i]
|
|
id := strings.ToLower(n.ResourceID)
|
|
if !strings.Contains(id, "epg_now_view") {
|
|
continue
|
|
}
|
|
d := abs(n.CY() - logo.CY())
|
|
if d < bestDist {
|
|
bestDist = d
|
|
best = n
|
|
}
|
|
}
|
|
if best == nil {
|
|
// Fallback: tap embedded player surface.
|
|
for i := range nodes {
|
|
n := &nodes[i]
|
|
id := strings.ToLower(n.ResourceID)
|
|
if strings.Contains(id, "video_view") || strings.Contains(id, "c5player") {
|
|
fmt.Printf("[*] tap player @ %d,%d\n", n.CX(), n.CY())
|
|
return c.Tap(n.CX(), n.CY())
|
|
}
|
|
}
|
|
return fmt.Errorf("Now cell not found")
|
|
}
|
|
fmt.Printf("[*] tap Now cell @ %d,%d\n", best.CX(), best.CY())
|
|
if err := c.Tap(best.CX(), best.CY()); err != nil {
|
|
return err
|
|
}
|
|
time.Sleep(time.Duration(a.cfg.Timeouts.AfterChannel))
|
|
return nil
|
|
}
|