Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
tools: philips-api.py names an address that carries a port, or a URL, instead of asking it
xbsheng00b641a1d489
diff --git a/tests/test_philips_api.py b/tests/test_philips_api.pyindex b750f987f..770e3fa02 100644--- a/tests/test_philips_api.py+++ b/tests/test_philips_api.py@@ -14,6 +14,11 @@ was simply asleep went looking for a package nothing had touched. That shape exinothing was learned; it is the rule tools/adb-closed.py and docs/TROUBLESHOOTING.md keep for port 5555 -only a refused connection is the TV speaking.+An address is the TV's own, not a TV_HOST written IP:port or a URL pasted from a browser: the two ports+below are added here, so `192.168.1.50:1926` built `https://192.168.1.50:1926:1926/6/system`, a name that+does not resolve, and the run answered "nothing answered, the set may be off" over an argument it could+not use. Both shapes are named before a URL is asked, with the address alone to pass.+Run from the repository root: python3 -m unittest discover -s tests -v"""import contextlib@@ -164,6 +169,63 @@ class ASilentTVIsNotADisabledPackage(unittest.TestCase):self.assertIn("org.droidtv.xtv", out)+class AnAddressThisCannotProbe(unittest.TestCase):+ """A TV_HOST written as tools/tv.py takes it (IP:port), and a URL pasted from a browser.++ Both reach find_api() as the host, and both build a URL that is not one - the address and a port of+ its own before the 1926 this adds - so the run answered "nothing answered on 1926 and 1925, the set+ may be off" for an argument it could not use, and an owner whose TV_HOST carries the ADB port went+ looking at the TV. Neither shape asks a URL now: the address alone is what the check takes.+ """++ def test_a_tv_host_with_a_port_is_named_before_a_url_is_asked(self):+ with mock.patch.dict("os.environ", {"TV_HOST": "192.168.1.50:1926"}):+ code, out, asked, err = run({}, argv=("philips-api.py",))+ self.assertEqual(code, 2)+ self.assertEqual(asked, [], "a URL built from IP:port was asked: %s" % asked)+ self.assertEqual(out, "")+ self.assertIn("192.168.1.50:1926 carries a port", err)+ self.assertIn("pass the TV's address alone: 192.168.1.50.", err)+ self.assertIn("TV_HOST", err)+ self.assertNotIn("nothing answered", err)+ self.assertNotIn("off, asleep", err)++ def test_an_address_with_a_port_on_the_command_line_is_the_same_mistake(self):+ code, out, asked, err = run({}, argv=("philips-api.py", "192.168.1.50:5555"))+ self.assertEqual(code, 2)+ self.assertEqual(asked, [])+ self.assertEqual(out, "")+ self.assertIn("192.168.1.50:5555 carries a port", err)+ self.assertIn("pass the TV's address alone: 192.168.1.50.", err)++ def test_a_url_is_named_too(self):+ for url in ("http://192.168.1.50", "https://tv.local"):+ with self.subTest(url=url):+ code, _, asked, err = run({}, argv=("philips-api.py", url))+ self.assertEqual(code, 2)+ self.assertEqual(asked, [])+ self.assertIn(f"{url} is a URL, not the TV's address", err)+ self.assertIn("without http:// or https://", err)++ def test_an_address_with_colons_that_is_not_a_port_is_still_probed(self):+ # A bracketed IPv6 address has colons and no port: the guard must leave it to find_api().+ code, _, asked, _ = run({}, argv=("philips-api.py", "[fe80::1]"))+ self.assertEqual(code, 2)+ self.assertEqual(["https://[fe80::1]:1926/6/system", "http://[fe80::1]:1925/6/system"], asked)++ def test_the_guard_reads_only_a_port_after_the_address(self):+ for host in ("192.168.1.50", "192.168.1.50.", "tv.local", "fe80::1", "[fe80::1]",+ "tv-1.local"):+ with self.subTest(host=host):+ self.assertIsNone(philips_api.address_problem(host))+ for host in ("192.168.1.50:1926", "tv.local:5555", "[fe80::1]:1926"):+ with self.subTest(host=host):+ self.assertIn("carries a port", philips_api.address_problem(host))+ for host in ("http://192.168.1.50", "https://tv.local", "HTTP://192.168.1.50"):+ with self.subTest(host=host):+ self.assertIn("is a URL", philips_api.address_problem(host))++class Answered(unittest.TestCase):"""The one judgement the exit code rests on, over the exceptions the socket layer hands over."""diff --git a/tools/philips-api.py b/tools/philips-api.pyindex af3fb20ab..f6b8c5978 100644--- a/tools/philips-api.py+++ b/tools/philips-api.py@@ -5,7 +5,8 @@Exits 0 when the API answers; 1 when a port answered and it is not the JointSpace API (the package tocheck is named); and 2 when this run could not tell - nothing answered on either port, so the TV may be-off, asleep, at another address or out of reach from here - or the command line was not one address.+off, asleep, at another address or out of reach from here - or the command line was not one address: a+URL, or an address carrying a port of its own, since the two ports this asks are the ones below.A port that refuses the connection is the TV answering: nothing listens there, which is what a disabledorg.droidtv.xtv looks like. A port that times out, answers "No route to host", or a name that does not@@ -30,6 +31,7 @@ answer: the endpoint is there.import errnoimport jsonimport os+import reimport socketimport sslimport sys@@ -37,6 +39,16 @@ import urllib.errorimport urllib.requestPORTS = ((1926, "https"), (1925, "http"))+# An address as tools/tv.py takes one in TV_HOST (the TV's IP, or IP:port for an adbd on a port of its+# own), and a URL pasted from a browser. Both reach find_api() as the host, and both then build a URL+# that is not one: https://192.168.1.50:1926:1926/6/system is a name that does not resolve, so the run+# answered "nothing answered on 1926 and 1925, the set may be off" - words about the TV's network for a+# mistake in the address - and an owner whose TV_HOST is set that way (the form tools/tv.py documents)+# went looking at the set instead of at the argument. The port in TV_HOST is the ADB port and means+# nothing to JointSpace, which this finds on 1926 and 1925 by itself, so the address alone is what the+# check takes.+HOST_PORT = re.compile(r"^(?:\[[^\]]+\]|[^:\[\]]+):\d+$")+URL_SCHEME = re.compile(r"^[A-Za-z][A-Za-z0-9+.-]*://")PROBE = ("ambilight/topology", "ambilight/power", "ambilight/mode", "ambilight/currentconfiguration","powerstate")# errno values that mean this computer never reached the TV: a timeout, a network that is not the@@ -114,12 +126,35 @@ def find_api(host):return None, None, reached+def address_problem(host):+ """Why `host` is not an address this check can probe, or None.++ tv.py's TV_HOST takes IP:port, and that port is the ADB one; a JointSpace API is on 1926 (Android+ TV) or 1925 (older sets), which find_api() tries itself. A URL is the other copy-paste shape.+ """+ if URL_SCHEME.match(host):+ return (f"{host} is a URL, not the TV's address: this check asks the address itself on "+ f"{PORTS[0][0]} and {PORTS[1][0]}, so pass it alone, without http:// or https://.")+ port = HOST_PORT.match(host)+ if port:+ address = host.rsplit(":", 1)[0]+ return (f"{host} carries a port, and this check asks the address itself on {PORTS[0][0]} and "+ f"{PORTS[1][0]}, so pass the TV's address alone: {address}.\n"+ f"TV_HOST is where that form comes from - tools/tv.py takes IP:port for its ADB "+ f"connection, and that port is the ADB port, not a JointSpace one.")+ return None++def main(argv):args = argv[1:]host = args[0] if args else os.environ.get("TV_HOST", "")if len(args) > 1 or not host or host.startswith("-"):print(__doc__.split("\n\n")[1], file=sys.stderr)return 2+ problem = address_problem(host)+ if problem:+ print(problem, file=sys.stderr)+ return 2base, info, reached = find_api(host)if not base: