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: wallpaper_prep.py prepares your own photos for a theme's wallpapers
anurag27018c7dd7294faa
diff --git a/README.md b/README.mdindex 8ee23c4ea..13c1411c7 100644--- a/README.md+++ b/README.md@@ -188,6 +188,7 @@ tools/restore.sh examples/xiaomi-mi-tv-4a/debloat.txt # undo it, stock latools/venv/bin/python -I tools/check.py examples/xiaomi-mi-tv-4a/debloat.txt # what a firmware update undidTV_HOST=192.168.1.50 launcher/build-and-install.sh # build the launcher and make it Hometools/theme.sh themes/aurora # push a theme; --reset removes it+python3 tools/wallpaper_prep.py ~/Pictures/trip mytheme/wallpapers # your photos, sized and darkened for the TV```| Tool | What it does |@@ -203,6 +204,7 @@ tools/theme.sh themes/aurora # push a theme; --r| [`tools/philips-api.py`](tools/philips-api.py) | Philips only: checks that the JointSpace control API Home Assistant uses still answers, before and after a debloat (`tools/venv/bin/python -I tools/philips-api.py <tv ip>`). Port 1926 over HTTPS first, then 1925; reads only what answers without pairing. || [`tools/privacy.py`](tools/privacy.py) | Audits the TV for voice, ACR and telemetry candidates and prints the evidence for each; `--write` turns the findings into a list `disable.sh` and `restore.sh` already understand. || [`tools/theme.sh`](tools/theme.sh), [`theme_restart.py`](tools/theme_restart.py) | Push a folder from [`themes/`](themes/) to the launcher and restart Home. |+| [`tools/wallpaper_prep.py`](tools/wallpaper_prep.py) | Turns a folder of your own photos (JPEG, PNG, WebP, HEIC) into darkened 1280×720 JPEGs under 300 KB for a theme's `wallpapers/` folder. Needs Pillow, plus pillow-heif for HEIC (`tools/requirements-photos.txt`). Never touches the originals. [How to use it](#your-own-photos-as-the-background). || [`tools/manage.py`](tools/manage.py) | List every add-on, theme and switch with its screenshot, see what is on the TV, and install, update or remove one by running its creator's own script. || [`tools/bench.py`](tools/bench.py) | Measures the launcher that answers HOME: key latency, how far the focus moved, janky frames, cold start, return to Home, and the idle CPU and PSS it costs. Changes nothing on the TV and writes the raw per-key numbers to JSON; no extra install. || [`tools/trace.py`](tools/trace.py), [`trace_report.py`](tools/trace_report.py) | Records Perfetto traces of the launcher (return to Home, cold start, D-pad) and reports where its time goes, per run and before against after. Optional: needs [`requirements-perf.txt`](tools/requirements-perf.txt). [Guide](tools/trace.md). |@@ -295,6 +297,59 @@ Themes, switches and add-ons together, with screenshots: [cleanyour.tv/addons](h**More:** [docs/launcher.md](docs/launcher.md) has the launcher settings page row by row, changing thedefault home, the languages, remote keys, the Clock screensaver, navigation and building it yourself.+<a id="your-own-photos-as-the-background"></a>+<details>+<summary><b>Your own photos as the background</b></summary>++A theme can rotate a folder of pictures behind Home, with no rebuild. No pictures ship with the repo: you bring+your own, and you decide you have the right to show them.++1. **Start a theme folder.** Copy a theme you like from [`themes/`](themes/), for example+ `themes/aurora`, into a new folder such as `mytheme/`, or start with an empty `config.json`.+2. **Prepare the photos.** A bright 12 MP photo is heavy for a 1 to 2 GB TV and drowns the clock and tiles.+ `tools/wallpaper_prep.py` centre-crops to 16:9, saves 1280×720 JPEGs under 300 KB, and darkens the picture+ itself, so `wallpaper_dim` can stay at 0. HEIC phone photos work. Your originals are never touched.++ ```bash+ python3 -m pip install -r tools/requirements-photos.txt+ python3 tools/wallpaper_prep.py ~/Pictures/trip mytheme/wallpapers+ ```++ Options: `--brightness 0.25` (0.1 to 1.0), `--gradient 0.6` (extra black toward the dock), `--size 1280x720`,+ `--max-kb 300`.+3. **Set the rotation** in `mytheme/config.json`:++ ```json+ { "wallpaper": true, "wallpaper_rotation_minutes": 1, "wallpaper_order": "shuffle", "wallpaper_dim": 0 }+ ```++ | Key | Notes |+ |---|---|+ | `wallpaper_rotation_minutes` | Whole minutes, 0 to 1440. **1 is the fastest.** `0` means no rotation, and a fraction such as `0.25` is read as `0`, which stops it. |+ | `wallpaper_order` | `shuffle` never shows the same picture twice in a row; `sequential` follows the file names. |+ | `wallpaper_dim` | Black overlay in percent. Leave at 0 when the pictures are already darkened. |+ | `dock_glass`, `dock_opacity` | A frosted-glass dock band (30 to 100%) so the picture shows behind the tiles. |+ | `greeting_name` | A name after the greeting: "Good evening, Sam". |+ | `show_stats`, `app_library`, `reduced_motion` | A stats line under the clock, an App library pill, calmer motion for weak GPUs. |++4. **Push it to the TV** (this restarts Home once, and keeps the Home-key helper working):++ ```bash+ tools/theme.sh mytheme # Windows: tools\theme.ps1 -TvHost 192.168.1.50 mytheme+ ```++ On the TV, **Launcher settings → Wallpaper** holds one picture, **None**, or **Theme default**, which+ rotates again.+5. **Take it off** with `tools/theme.sh --reset`.++What it cannot do: there is no crossfade (the picture changes with a cut), no rotation faster than a minute, and+the Clock screensaver shows time and date only, never photos. Without a `wallpapers/` folder the theme still+works and Home keeps its plain colour. A picture is decoded into memory while Home shows it: about 4 MB at 1080p+in the default 16-bit colour, 8 MB with `wallpaper_true_color` (see [themes/README.md](themes/README.md)), so keep+the pictures small on a 1 GB TV.++</details>+## Restoring your TVKeep the list you applied. One line puts the TV back the way it was:diff --git a/tests/test_wallpaper_prep.py b/tests/test_wallpaper_prep.pynew file mode 100644index 000000000..d48bf42b3--- /dev/null+++ b/tests/test_wallpaper_prep.py@@ -0,0 +1,105 @@+"""tools/wallpaper_prep.py: size, darkening, numbering, the size limit and the refusals."""+import importlib.util+import os+import tempfile+import unittest+from pathlib import Path++ROOT = Path(__file__).resolve().parent.parent+SPEC = importlib.util.spec_from_file_location("wallpaper_prep", ROOT / "tools" / "wallpaper_prep.py")+prep = importlib.util.module_from_spec(SPEC)+SPEC.loader.exec_module(prep)++try:+ from PIL import Image+except ImportError: # the tool needs Pillow; the rest of the repo does not+ Image = None+++def make_photo(path, size=(400, 300), colour=(220, 200, 180)):+ Image.new("RGB", size, colour).save(path)+++class ParseSizeTest(unittest.TestCase):+ def test_accepts_width_x_height(self):+ self.assertEqual(prep.parse_size("1280x720"), (1280, 720))+ self.assertEqual(prep.parse_size("1920X1080"), (1920, 1080))++ def test_refuses_nonsense(self):+ for bad in ("1280", "axb", "10x5", "99999x720", ""):+ with self.subTest(bad=bad):+ with self.assertRaises(Exception):+ prep.parse_size(bad)+++class SourceFilesTest(unittest.TestCase):+ def test_only_pictures_in_name_order(self):+ with tempfile.TemporaryDirectory() as d:+ for name in ("b.JPG", "a.png", "notes.txt", "c.webp", "d.heic"):+ Path(d, name).write_bytes(b"x")+ os.mkdir(Path(d, "sub.jpg"))+ names = [os.path.basename(p) for p in prep.source_files(d)]+ self.assertEqual(names, ["a.png", "b.JPG", "c.webp", "d.heic"])++[email protected](Image is None, "Pillow not installed")+class PrepareTest(unittest.TestCase):+ def test_output_is_1280x720_jpeg_and_darker(self):+ with tempfile.TemporaryDirectory() as d:+ src, out = Path(d, "in.png"), Path(d, "out.jpg")+ make_photo(src)+ kb, quality = prep.prepare(str(src), str(out), (1280, 720), 0.25, 0.6, 84, 300)+ with Image.open(out) as result:+ self.assertEqual(result.size, (1280, 720))+ self.assertEqual(result.format, "JPEG")+ top = result.getpixel((640, 5))+ bottom = result.getpixel((640, 715))+ self.assertLess(sum(top), sum((220, 200, 180)) * 0.35, "top should be much darker than the source")+ self.assertLess(sum(bottom), sum(top), "bottom should be darker than top")+ self.assertLessEqual(kb, 300)++ def test_quality_drops_until_the_limit_fits(self):+ with tempfile.TemporaryDirectory() as d:+ src, out = Path(d, "noise.png"), Path(d, "out.jpg")+ Image.effect_noise((1280, 720), 80).convert("RGB").save(src)+ full_kb, full_quality = prep.prepare(str(src), str(out), (1280, 720), 1.0, 0.0, 90, 10_000)+ self.assertEqual(full_quality, 90, "a limit it already meets keeps the starting quality")+ limit = int(full_kb * 0.8)+ kb, quality = prep.prepare(str(src), str(out), (1280, 720), 1.0, 0.0, 90, limit)+ self.assertLess(quality, 90)+ self.assertLessEqual(kb, limit)++ def test_an_impossible_limit_stops_at_the_quality_floor(self):+ with tempfile.TemporaryDirectory() as d:+ src, out = Path(d, "noise.png"), Path(d, "out.jpg")+ Image.effect_noise((1280, 720), 80).convert("RGB").save(src)+ kb, quality = prep.prepare(str(src), str(out), (1280, 720), 1.0, 0.0, 90, 5)+ self.assertLessEqual(quality, 50)+ self.assertGreater(kb, 5, "it reports the size it could reach instead of looping forever")++ def test_originals_are_never_overwritten_and_target_must_differ(self):+ with tempfile.TemporaryDirectory() as d:+ make_photo(Path(d, "a.png"))+ with self.assertRaises(SystemExit):+ prep.main([d, d])++ def test_main_numbers_the_outputs_and_skips_a_corrupt_file(self):+ with tempfile.TemporaryDirectory() as d:+ src, out = Path(d, "src"), Path(d, "out")+ src.mkdir()+ make_photo(src / "a.png")+ (src / "b.jpg").write_bytes(b"not a picture")+ make_photo(src / "c.png", colour=(10, 20, 30))+ self.assertEqual(prep.main([str(src), str(out)]), 0)+ self.assertEqual(sorted(os.listdir(out)), ["01.jpg", "03.jpg"])++ def test_empty_folder_exits_with_a_message(self):+ with tempfile.TemporaryDirectory() as d:+ src = Path(d, "src")+ src.mkdir()+ with self.assertRaises(SystemExit):+ prep.main([str(src), str(Path(d, "out"))])+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/requirements-photos.txt b/tools/requirements-photos.txtnew file mode 100644index 000000000..5aa50c68b--- /dev/null+++ b/tools/requirements-photos.txt@@ -0,0 +1,2 @@+pillow==13.0.0+pillow-heif==1.8.1diff --git a/tools/wallpaper_prep.py b/tools/wallpaper_prep.pynew file mode 100644index 000000000..aa6453149--- /dev/null+++ b/tools/wallpaper_prep.py@@ -0,0 +1,127 @@+"""Turns a folder of your own photos into wallpapers the launcher can show on a small TV.++ python tools/wallpaper_prep.py ~/Pictures/trip /tmp/my-theme/wallpapers++Every JPEG, PNG, WebP and (with pillow-heif) HEIC file in the first folder is centre-cropped to 16:9, shrunk to+1280x720, darkened so the clock, the grid and the dock stay readable, and saved as 01.jpg, 02.jpg, ... in the+second folder. The originals are never touched. Each picture is kept under --max-kb (300 by default, what+themes/README.md asks for) by lowering the JPEG quality a step at a time.++The darkening is painted into the picture, so wallpaper_dim can stay at 0 and the launcher draws no shade+layer. The numbers that worked on a Xiaomi Mi Box S (2 GB) are the defaults: brightness 0.25 and a gradient+that adds up to 60% black toward the bottom, where the dock sits.++Needs Pillow; HEIC (iPhone and many Android cameras) also needs pillow-heif:++ python -m pip install -r tools/requirements-photos.txt++Use pictures you have the right to show.+"""+import argparse+import os+import sys++EXTENSIONS = {".jpg", ".jpeg", ".png", ".webp", ".heic", ".heif"}+++def parse_size(text):+ try:+ w, h = text.lower().split("x")+ w, h = int(w), int(h)+ except ValueError:+ raise argparse.ArgumentTypeError("size must look like 1280x720")+ if w < 16 or h < 9 or w > 7680 or h > 4320:+ raise argparse.ArgumentTypeError("size must be between 16x9 and 7680x4320")+ return w, h+++def source_files(folder):+ """Picture files directly inside folder, in name order (so the numbering is stable)."""+ names = sorted(n for n in os.listdir(folder) if os.path.splitext(n)[1].lower() in EXTENSIONS)+ return [os.path.join(folder, n) for n in names if os.path.isfile(os.path.join(folder, n))]+++def darken(image, brightness, gradient):+ """Scale brightness, then blend toward black from top (0) to bottom (gradient)."""+ from PIL import Image, ImageEnhance+ image = ImageEnhance.Brightness(image).enhance(brightness)+ if gradient > 0:+ mask = Image.linear_gradient("L").resize(image.size).point(lambda v: int(v * gradient))+ image = Image.composite(Image.new("RGB", image.size, (0, 0, 0)), image, mask)+ return image+++def prepare(path, out_path, size, brightness, gradient, quality, max_kb):+ """Writes one wallpaper and returns (size in KB, JPEG quality used)."""+ from PIL import Image, ImageOps+ with Image.open(path) as opened:+ image = ImageOps.exif_transpose(opened).convert("RGB")+ image = ImageOps.fit(image, size, Image.LANCZOS, centering=(0.5, 0.5))+ image = darken(image, brightness, gradient)+ q = quality+ while True:+ image.save(out_path, "JPEG", quality=q, optimize=True)+ kb = os.path.getsize(out_path) / 1024+ if kb <= max_kb or q <= 50:+ return round(kb), q+ q -= 6+++def main(argv=None):+ parser = argparse.ArgumentParser(description="Resize and darken photos for the launcher's wallpaper folder.")+ parser.add_argument("source", help="folder with your photos")+ parser.add_argument("target", help="folder to write 01.jpg, 02.jpg, ... into (created if missing)")+ parser.add_argument("--size", type=parse_size, default=(1280, 720), help="default 1280x720")+ parser.add_argument("--brightness", type=float, default=0.25, help="0.1 to 1.0, default 0.25")+ parser.add_argument("--gradient", type=float, default=0.6, help="extra black toward the bottom, 0 to 0.9, default 0.6")+ parser.add_argument("--quality", type=int, default=84, help="starting JPEG quality, default 84")+ parser.add_argument("--max-kb", type=int, default=300, help="size limit per picture, default 300")+ args = parser.parse_args(argv)++ if not 0.1 <= args.brightness <= 1.0:+ parser.error("--brightness must be between 0.1 and 1.0")+ if not 0 <= args.gradient <= 0.9:+ parser.error("--gradient must be between 0 and 0.9")+ if not 30 <= args.quality <= 95:+ parser.error("--quality must be between 30 and 95")+ if not os.path.isdir(args.source):+ parser.error(f"{args.source} is not a folder")+ if os.path.abspath(args.source) == os.path.abspath(args.target):+ parser.error("the target must be a different folder: the originals are never overwritten")++ try:+ import PIL # noqa: F401+ except ImportError:+ sys.exit("Pillow is missing: python -m pip install -r tools/requirements-photos.txt")+ try:+ import pillow_heif+ pillow_heif.register_heif_opener()+ except ImportError:+ pillow_heif = None++ files = source_files(args.source)+ if not files:+ sys.exit(f"no JPEG, PNG, WebP or HEIC pictures in {args.source}")+ os.makedirs(args.target, exist_ok=True)++ written = 0+ for number, path in enumerate(files, 1):+ name = os.path.basename(path)+ if os.path.splitext(name)[1].lower() in {".heic", ".heif"} and pillow_heif is None:+ print(f"skipped {name}: HEIC needs pillow-heif (python -m pip install -r tools/requirements-photos.txt)")+ continue+ out_path = os.path.join(args.target, "%02d.jpg" % number)+ try:+ kb, quality = prepare(path, out_path, args.size, args.brightness, args.gradient, args.quality, args.max_kb)+ except Exception as error: # a corrupt picture must not stop the rest+ print(f"skipped {name}: {error}")+ continue+ written += 1+ note = "" if kb <= args.max_kb else f" (over {args.max_kb} KB even at quality {quality})"+ print(f"{os.path.basename(out_path)} <- {name} {kb} KB, quality {quality}{note}")+ print(f"{written} of {len(files)} pictures written to {args.target}")+ return 0 if written else 1+++if __name__ == "__main__":+ sys.exit(main())