Canonicalize validated managed proxy schemes to socks5h for Player, metadata, resource and warmup probes; retain listener ownership, TLS/privacy checks and legacy CLI/pinned checker semantics. Stop canceled inventory requests before Player and metadata fallback, with explicit cancellation and runner-only DNS regressions. Verification: full native Go tests, affected race tests, go vet and static/config/supervision fixtures passed. An extra whole-package race attempt exceeded its 180s deadline in unrelated TestTuneCLI; affected race coverage completed separately. Co-authored-by: GPT-6 <gpt-6@openai.com>
112 lines
4.0 KiB
Go
112 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"os"
|
|
)
|
|
|
|
const usage = `Usage: zapret-autotune <command>
|
|
|
|
Commands:
|
|
status Show latest recorded tune run/proposal (not live service health)
|
|
history [--limit N] List recorded tune attempts (default 20; proposals not active)
|
|
strategies youtube List recorded proposals by group (not active)
|
|
discover youtube --video-id ID --proxy socks5://HOST:PORT
|
|
Discover cache hostname only (no media-transfer check)
|
|
health youtube One-shot Player API health through configured loopback SOCKS
|
|
managed init|reconcile|status|apply|monitor
|
|
Guarded activation/monitoring in the dedicated managed-test target only
|
|
check youtube Refuse checks until probe URLs/video IDs are configured and agreed
|
|
tune youtube Test youtube.com frontend only; print options without applying
|
|
tune googlevideo --video-id ID --proxy socks5://HOST:PORT
|
|
Discover and verify one exact cache host; proposal only
|
|
recover googlevideo --video-id ID --proxy socks5://HOST:PORT
|
|
Recheck saved scenarios before scanning; proposal, not active
|
|
render <json-file> Select normalized offline results and print NFQWS2_OPT
|
|
`
|
|
|
|
func main() {
|
|
os.Exit(run(os.Args[1:], os.Stdout, os.Stderr))
|
|
}
|
|
|
|
func run(args []string, stdout, stderr io.Writer) int {
|
|
return runWithPlayer(args, stdout, stderr, runPlayerCurl)
|
|
}
|
|
|
|
func runWithPlayer(args []string, stdout, stderr io.Writer, player playerRunner) int {
|
|
if len(args) == 1 && args[0] == "target-config-check" {
|
|
if _, err := parseManagedHealthConfig(os.LookupEnv); err != nil {
|
|
fmt.Fprintln(stderr, "configerror: invalid target health/service configuration")
|
|
return 64
|
|
}
|
|
if dns := os.Getenv("SS_DNS_SERVER"); dns != "" && net.ParseIP(dns) == nil {
|
|
fmt.Fprintln(stderr, "configerror: SS_DNS_SERVER requires a literal IPv4 or IPv6 address")
|
|
return 64
|
|
}
|
|
return 0
|
|
}
|
|
if len(args) > 0 && args[0] == "managed" {
|
|
return managedCLI(args[1:], stdout, stderr, managedDependencies(player))
|
|
}
|
|
if len(args) == 2 && args[0] == "health" && args[1] == "youtube" {
|
|
return healthYoutube(stdout, stderr, player)
|
|
}
|
|
if len(args) >= 2 && args[0] == "recover" && args[1] == "googlevideo" {
|
|
return recoverGooglevideo(args[2:], stdout, stderr, player, runBlockcheck, runCombinedBlockcheckForHost)
|
|
}
|
|
if len(args) >= 2 && args[0] == "tune" && args[1] == "googlevideo" {
|
|
return tuneGooglevideo(args[2:], stdout, stderr, player, runBlockcheck, runCombinedBlockcheckForHost)
|
|
}
|
|
if len(args) > 0 && args[0] == "history" {
|
|
return history(args[1:], stdout, stderr)
|
|
}
|
|
if len(args) == 2 && args[0] == "strategies" && args[1] == "youtube" {
|
|
return strategiesYoutube(stdout, stderr)
|
|
}
|
|
if len(args) == 2 && args[0] == "tune" && args[1] == "youtube" {
|
|
return tuneYoutube(stdout, stderr, runBlockcheck)
|
|
}
|
|
if len(args) == 2 && args[0] == "render" {
|
|
file, err := os.Open(args[1])
|
|
if err != nil {
|
|
fmt.Fprintln(stderr, "error: cannot open results:", err)
|
|
return 1
|
|
}
|
|
defer file.Close()
|
|
output, err := renderResults(file)
|
|
if err != nil {
|
|
fmt.Fprintln(stderr, "error: cannot render results:", err)
|
|
return 1
|
|
}
|
|
if _, err := fmt.Fprintln(stdout, output); err != nil {
|
|
fmt.Fprintln(stderr, "error: cannot write results:", err)
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
if len(args) == 1 {
|
|
switch args[0] {
|
|
case "status":
|
|
return status(stdout, stderr)
|
|
case "help", "--help", "-h":
|
|
if _, err := fmt.Fprint(stdout, usage); err != nil {
|
|
fmt.Fprintln(stderr, "error: cannot write usage:", err)
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
}
|
|
if len(args) >= 2 && args[0] == "discover" && args[1] == "youtube" {
|
|
return discoverYoutube(args[2:], stdout, stderr, player)
|
|
}
|
|
if len(args) == 2 && args[0] == "check" && args[1] == "youtube" {
|
|
fmt.Fprintln(stderr, "error: check youtube is unavailable: YouTube probe URLs/video IDs have not been configured or agreed. No network requests were made; production health was not checked.")
|
|
return 1
|
|
}
|
|
fmt.Fprintln(stderr, "error: missing, unknown, or unsupported command/arguments")
|
|
fmt.Fprint(stderr, usage)
|
|
return 2
|
|
}
|