#!/bin/bash
# Reproduces every test behind the guide "subtitles show boxes instead of letters" (2026-11-29).
# Needs: ffmpeg built with libass, fontconfig, python3 with fonttools (pip install fonttools), node with playwright
# for the two live tool checks, curl, iconv. Run in a folder that holds only the scripts below; it downloads about 12 MB.
# Put the scripts from the same folder next to it first: make-srt.py, cmap-check.py, burn-tests.sh, inspector-check.cjs, burn-tool-check.cjs, run-commands.sh, srt-chars.py, mkotf.py.
set -u
G=https://raw.githubusercontent.com/google/fonts/main
C=https://raw.githubusercontent.com/unicode-org/cldr-json/main/cldr-json/cldr-misc-full/main
mkdir -p src fonts srt
# 1. Sources: CLDR 49 letter sets, five fonts with their licenses, one public-domain clip
for l in vi pl tr cs ru en; do curl -sfL -o src/cldr-$l-characters.json $C/$l/characters.json; done
curl -sfL -o fonts/BebasNeue-Regular.ttf $G/ofl/bebasneue/BebasNeue-Regular.ttf
curl -sfL -o fonts/BeVietnamPro-Bold.ttf $G/ofl/bevietnampro/BeVietnamPro-Bold.ttf
curl -sfL -o fonts/PermanentMarker-Regular.ttf $G/apache/permanentmarker/PermanentMarker-Regular.ttf
curl -sfL -o fonts/TitanOne-Regular.ttf $G/ofl/titanone/TitanOne-Regular.ttf
curl -sfL -o fonts/Inter-Bold.ttf https://koldflux.com/fonts/subtitles/Inter-Bold.ttf
curl -sfL -o src/falls-creek.webm "https://upload.wikimedia.org/wikipedia/commons/f/fa/Waterfall_on_Falls_Creek%2C_south_of_Augusta%2C_Montana_%2852974925584%29.webm" \
  || echo "download the clip by hand from https://commons.wikimedia.org/wiki/File:Waterfall_on_Falls_Creek,_south_of_Augusta,_Montana_(52974925584).webm into src/falls-creek.webm"
ffmpeg -v error -y -i src/falls-creek.webm -t 20 -c:v libx264 -crf 20 -preset veryfast -c:a aac -b:a 128k video.mp4
# 2. Test subtitle files: en control + vi pl tr cs ru, and vi in NFD
python3 make-srt.py srt
# 3. Which letters each font lacks (fontTools cmap), with controls
python3 cmap-check.py fonts src srt . > cmap.log
# 4. Burn tests: normal fallback (A), no fallback fonts (B), the fix (C); frames at 6 s and 14 s
bash burn-tests.sh
# 5. Live Koldflux tools in headless Chromium
node inspector-check.cjs fonts srt .
for L in vi ru; do mkdir -p tool-$L; cp video.mp4 tool-$L/source.mp4; cp srt/$L.srt tool-$L/captions.srt; node burn-tool-check.cjs tool-$L; done
# 6. Every published command plus edge inputs
bash run-commands.sh
