Files
OrbitTv/tools/import-brand-kit.py
T
pauljdandClaude Opus 5.5 15daa37761 Keep the Blender idents, with the new logo on them (build 59)
Paul, 17 November 2026: "keep them and just replace the logo on top". The 26 Blender channel idents and the Blender
block idents are re-made on their own kept scenes with the Planet O lockup where the old logo went, each with its own
sound; Vortex Prime and Afterburn had their 3D rendered again. Saturday and Sunday Mornings carry the new channel
logos. Ring X nights go back to one shared clip with the night drawn over it. Riot's blocks keep the flat new-style
versions, as their old logo is the scene. tools/import-planet-o-idents.sh puts them in place after the kit import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 21:21:40 +00:00

127 lines
9.4 KiB
Python

#!/usr/bin/env python3
"""Brings the approved Orbit brand kit (Planet O and Sunset Stripes, Paul, 17 November 2026) into the app's resources.
python3 tools/import-brand-kit.py ~/Documents/OrbitTV/brand-kit/orbit-brand
Reads the kit's channel folders and app-stage/ (app-sized guide logos and the wordmark, rendered by the kit's
source/guide-app.js and source/wordmark-app.js), and writes:
- each channel's guide logo (ChannelBranding.logo) and corner logo (.bug, the white version)
- each channel's ident: the kit's 4.5 s ident held on its end frame to the app's ident length, 1280x720, carrying the
channel's own ident sound from before the rebrand (taken from git, so this can be run again)
- the ORBIT wordmark, app icon, launcher icons, TV banner, the welcome moment (network sign-on) and the tuning moment
(loading screen)
Channels are matched by number to the kit's folders, never by any number inside the kit.
"""
import os, re, subprocess, sys, tempfile
KIT = os.path.abspath(os.path.expanduser(sys.argv[1] if len(sys.argv) > 1 else "~/Documents/OrbitTV/brand-kit/orbit-brand"))
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
RES = os.path.join(ROOT, "android/app/src/main/res")
JAVA = os.path.join(ROOT, "android/app/src/main/java/tv/orbit/classic")
SOUND_FROM = os.environ.get("ORBIT_SOUND_FROM", "ux-0.129") # the branch whose idents carry the sounds
SLUGS = {101: "orbit-1", 102: "orbit-2", 103: "orbit-three", 104: "orbit-gold", 105: "orbit-riot", 106: "orbit-paradox",
107: "orbit-evidence", 108: "orbit-play", 109: "orbit-signature", 110: "orbit-unscripted", 201: "orbit-terra",
202: "orbit-odyssey", 203: "orbit-wild", 204: "orbit-dark-files", 205: "orbit-kitchen", 206: "orbit-home",
300: "orbit-drive-in", 301: "orbit-premiere", 302: "orbit-action", 303: "orbit-sci-fi", 304: "orbit-horror",
305: "orbit-after-dark", 306: "orbit-vhs", 307: "orbit-romance", 308: "orbit-detour", 309: "orbit-britx",
310: "orbit-christmas", 401: "orbit-ring-x", 601: "orbit-vortex", 602: "orbit-heroes", 603: "orbit-x",
604: "orbit-rewind", 605: "orbit-toonz", 611: "orbit-junior", 612: "orbit-wonder", 613: "orbit-pixelz", 614: "orbit-tots"}
NAMED = {"TOTS_NUMBER": 614, "DRIVE_IN_NUMBER": 300, "VORTEX_NUMBER": 601, "CHRISTMAS_NUMBER": 310, "AFTER_DARK_NUMBER": 305}
PACKS = {"orbit-mistletoe": "orbit-mistletoe", "orbit-sakura": "orbit-sakura"}
def run(*cmd): subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
def need(path):
if not os.path.exists(path): sys.exit(f"Missing from the kit: {path}")
return path
def webp(src, out, lossless=True):
run("ffmpeg", "-y", "-loglevel", "error", "-i", need(src), "-c:v", "libwebp", "-lossless", "1" if lossless else "0", "-q:v", "90", out)
def duration(path):
return float(subprocess.check_output(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", path]).decode().strip())
def original(rel):
"""The file as it was on SOUND_FROM, so a second run still takes the old sound, not the new file's."""
data = subprocess.check_output(["git", "-C", ROOT, "show", f"{SOUND_FROM}:android/app/src/main/{rel}"])
f = tempfile.NamedTemporaryFile(suffix=os.path.splitext(rel)[1], delete=False); f.write(data); f.close()
return f.name
def ident(src, rel_out):
"""The kit ident held on its end frame for as long as the old one ran, with the old one's sound."""
old = original(rel_out)
length = duration(old)
has_audio = subprocess.check_output(["ffprobe", "-v", "error", "-select_streams", "a", "-show_entries", "stream=index", "-of", "csv=p=0", old]).strip() != b""
cmd = ["ffmpeg", "-y", "-loglevel", "error", "-i", need(src)]
if has_audio: cmd += ["-i", old]
cmd += ["-filter_complex", f"[0:v]scale=1280:720:flags=lanczos,tpad=stop_mode=clone:stop_duration={length},trim=duration={length},fps=30,format=yuv420p[v]",
"-map", "[v]"]
if has_audio: cmd += ["-map", "1:a", "-c:a", "copy"]
cmd += ["-c:v", "libx264", "-preset", "slow", "-crf", "20", "-movflags", "+faststart", "-t", f"{length}", os.path.join(ROOT, "android/app/src/main", rel_out)]
run(*cmd); os.unlink(old)
def brand_table():
"""number -> (logo, bug) resource names, read from ChannelBranding.kt."""
text = open(os.path.join(JAVA, "ChannelBranding.kt")).read()
out = {}
for key, logo, bug in re.findall(r'^\s*(\w+) to ChannelBranding\("[^"]+", "[^"]+", R\.drawable\.(\w+), R\.drawable\.\w+, R\.drawable\.(\w+)', text, re.M):
out[int(key) if key.isdigit() else NAMED[key]] = (logo, bug)
packs = dict((slug, (logo, bug)) for slug, logo, bug in re.findall(r'"(orbit-\w+)" to ChannelBranding\("[^"]+", "[^"]+", R\.drawable\.(\w+), R\.drawable\.\w+, R\.drawable\.(\w+)', text))
return out, packs
def main():
stage = os.path.join(KIT, "app-stage")
table, packs = brand_table()
missing = sorted(set(table) - set(SLUGS))
if missing: sys.exit(f"No kit folder mapped for channels {missing}")
nodpi = os.path.join(RES, "drawable-nodpi")
logos = [(SLUGS[n], *table[n]) for n in sorted(table)] + [(PACKS[s], *packs[s]) for s in sorted(packs)]
for slug, logo, bug in logos:
webp(os.path.join(stage, f"{slug}-logo.png"), os.path.join(nodpi, f"{logo}.webp"))
webp(os.path.join(KIT, "channels", slug, f"{slug}-corner-logo-white@2x.png"), os.path.join(nodpi, f"{bug}.webp"))
print(f"logos and corner logos: {len(logos)} channels")
idents = sorted(int(n) for n in re.findall(r'R\.raw\.ident_(\d+)\b', open(os.path.join(JAVA, "Idents.kt")).read()))
for n in idents:
ident(os.path.join(KIT, "channels", SLUGS[n], f"{SLUGS[n]}-ident.mp4"), f"res/raw/ident_{n}.mp4")
for name in ("614_morning", "614_morning_roll", "614_evening"):
ident(os.path.join(KIT, "channels", "orbit-tots", "orbit-tots-ident.mp4"), f"res/raw/ident_{name}.mp4")
for slug, name in (("orbit-mistletoe", "mistletoe"), ("orbit-sakura", "sakura")):
ident(os.path.join(KIT, "channels", slug, f"{slug}-ident.mp4"), f"res/raw/ident_{name}.mp4")
ident(os.path.join(KIT, "channels", "orbit-drive-in", "orbit-drive-in-ident.mp4"), "res/raw/drive_in_intro.mp4")
print(f"idents: {len(idents) + 6}, with the Drive-In intro")
# Riot's block idents: rendered by the kit's source/block-render.js from source/blocks.json, 4 s, silent (each has a
# sting). The other blocks keep their Blender scenes with the new logo: tools/import-planet-o-idents.sh, run after this.
blocks = sorted(f for f in os.listdir(need(os.path.join(KIT, "blocks"))) if f.startswith("block_riot_") and f.endswith(".mp4"))
for f in blocks: run("cp", os.path.join(KIT, "blocks", f), os.path.join(RES, "raw", f))
print(f"block idents: {len(blocks)}")
po = os.path.join(KIT, "planet-o")
webp(os.path.join(stage, "wordmark.png"), os.path.join(nodpi, "orbit_logo.webp"))
webp(os.path.join(po, "android", "play-store-icon-512.png"), os.path.join(nodpi, "orbit_app_icon.webp"))
run("cp", need(os.path.join(po, "android", "tv-banner", "drawable-xhdpi", "banner.png")), os.path.join(nodpi, "orbit_banner.png"))
for d in ("mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"):
os.makedirs(os.path.join(RES, f"mipmap-{d}"), exist_ok=True)
for f in ("ic_launcher.png", "ic_launcher_round.png"):
run("cp", need(os.path.join(po, "android", f"mipmap-{d}", f)), os.path.join(RES, f"mipmap-{d}", f))
os.makedirs(os.path.join(RES, "mipmap-xxxhdpi"), exist_ok=True)
for layer in ("background", "foreground", "monochrome"):
run("cp", need(os.path.join(po, "android", "adaptive", f"ic_launcher_{layer}.png")), os.path.join(RES, "mipmap-xxxhdpi", f"ic_launcher_{layer}.png"))
os.makedirs(os.path.join(RES, "mipmap-anydpi-v26"), exist_ok=True)
adaptive = ('<?xml version="1.0" encoding="utf-8"?>\n<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">\n'
' <background android:drawable="@mipmap/ic_launcher_background" />\n <foreground android:drawable="@mipmap/ic_launcher_foreground" />\n'
' <monochrome android:drawable="@mipmap/ic_launcher_monochrome" />\n</adaptive-icon>\n')
for f in ("ic_launcher.xml", "ic_launcher_round.xml"): open(os.path.join(RES, "mipmap-anydpi-v26", f), "w").write(adaptive)
raw = os.path.join(RES, "raw")
sign_on = need(os.path.join(po, "screens", "network-sign-on.mp4"))
run("ffmpeg", "-y", "-loglevel", "error", "-i", sign_on, "-vf", "scale=1280:720:flags=lanczos,format=yuv420p", "-an", "-c:v", "libx264", "-preset", "slow", "-crf", "20", "-movflags", "+faststart", os.path.join(raw, "moment_welcome.mp4"))
run("ffmpeg", "-y", "-loglevel", "error", "-sseof", "-0.1", "-i", sign_on, "-frames:v", "1", "-vf", "scale=1280:720:flags=lanczos", "-c:v", "libwebp", "-q:v", "90", os.path.join(nodpi, "moment_welcome_still.webp"))
loading = need(os.path.join(po, "screens", "loading-screen-1920x1080.png"))
run("ffmpeg", "-y", "-loglevel", "error", "-loop", "1", "-i", loading, "-t", "2", "-r", "30", "-vf", "scale=1280:720:flags=lanczos,format=yuv420p", "-an", "-c:v", "libx264", "-preset", "slow", "-crf", "20", "-tune", "stillimage", "-movflags", "+faststart", os.path.join(raw, "moment_tuning.mp4"))
run("ffmpeg", "-y", "-loglevel", "error", "-i", loading, "-vf", "scale=1280:720:flags=lanczos", "-c:v", "libwebp", "-q:v", "90", os.path.join(nodpi, "moment_tuning_still.webp"))
print("wordmark, icons, banner, welcome and tuning moments: done")
if __name__ == "__main__":
main()