#!/usr/bin/env python3 """ Inject the ARRFLIX runtime branding shim into web-overrides/index.html. Idempotent: if the shim is already present, exits 0 with a notice. """ import sys, pathlib, re ROOT = pathlib.Path(__file__).resolve().parent.parent TARGET = ROOT / "web-overrides" / "index.html" MARKER_BEGIN = "/* ARRFLIX-SHIM-BEGIN */" MARKER_END = "/* ARRFLIX-SHIM-END */" SHIM = MARKER_BEGIN + r""" (function(){ var TITLE = 'ARRFLIX'; var BARE_RE = /^Jellyfin$/i; function getFavicon(){ var l = document.querySelector('link[rel="shortcut icon"], link[rel="icon"]'); return l && l.href ? l.href : null; } function lockTitle(){ try { var t = document.title || ''; if (BARE_RE.test(t)) { document.title = TITLE; return; } if (/Jellyfin/i.test(t)) { var cleaned = t.replace(/\s*[-|]\s*Jellyfin\s*$/i, '').replace(/Jellyfin/gi, TITLE); if (!cleaned) { document.title = TITLE; } else if (!/ARRFLIX/i.test(cleaned)) { document.title = cleaned + ' - ' + TITLE; } else { document.title = cleaned; } } } catch(e){} } function lockFavicon(){ try { var fav = getFavicon(); if (!fav || fav.indexOf('data:image') !== 0) return; var icons = document.querySelectorAll('link[rel*="icon"]'); for (var i=0;i" def main(): html = TARGET.read_text(encoding="utf-8") if MARKER_BEGIN in html: # Replace the existing shim block in place pattern = re.compile(r"", re.DOTALL) new_html, n = pattern.subn(WRAPPED, html, count=1) if n != 1: print("ERROR: shim markers present but could not match for replacement", file=sys.stderr) sys.exit(2) TARGET.write_text(new_html, encoding="utf-8") print(f"Replaced existing shim ({len(WRAPPED)} chars).") return # Insert immediately after needle = "" idx = html.find(needle) if idx < 0: print("ERROR: not found in target", file=sys.stderr) sys.exit(1) insert_at = idx + len(needle) new_html = html[:insert_at] + WRAPPED + html[insert_at:] TARGET.write_text(new_html, encoding="utf-8") print(f"Inserted shim ({len(WRAPPED)} chars) after at offset {insert_at}.") if __name__ == "__main__": main()