#!/bin/bash
# NERDLETTER NUMBERS STATION MP4 GENERATOR
# Lincolnshire Poacher style — retro drama for the Day Book crowd

MESSAGE="$1"          # e.g. "HLXIB JACJP ERXHN EFM"
PAGE="$2"             # e.g. 001
EPISODE="${3:-01}"    # Secret Message number

OUTFILE="nerdletter_secret_${EPISODE}_page${PAGE}.mp4"
TMP_WAV="temp_voice.wav"
TMP_VIDEO="temp_bg.mp4"

echo "=== NERDLETTER SECRET TRANSMISSION #${EPISODE} ==="
echo "Page ${PAGE} — Generating spoken MP4..."

# 1. Create spoken audio (female voice, slow, numbers-station style)
echo "NERDLETTER SECRET MESSAGE ${EPISODE}. USE DAY BOOK PAGE ${PAGE}. ${MESSAGE}" | \
espeak-ng -ven+f3 -s120 -k20 -a 150 -w "$TMP_WAV" \
  --punct="" --sep=" " 2>/dev/null

# 2. Create simple retro video background (black screen with green text, 15 seconds)
ffmpeg -f lavfi -i color=black:s=1280x720:d=15 \
  -vf "drawtext=font='Courier':fontsize=48:fontcolor=green@0.9:text='NERDLETTER SECRET TRANSMISSION #${EPISODE}':x=(w-text_w)/2:y=80,
       drawtext=font='Courier':fontsize=36:fontcolor=green@0.8:text='USE DAY BOOK PAGE ${PAGE}':x=(w-text_w)/2:y=160,
       drawtext=font='Courier':fontsize=42:fontcolor=lime:text='${MESSAGE}':x=(w-text_w)/2:y=280:box=1:boxcolor=black@0.6:boxborderw=10,
       drawtext=font='Courier':fontsize=28:fontcolor=green@0.7:text='DESTROY PAGE AFTER USE':x=(w-text_w)/2:y=620" \
  -c:v libx264 -t 15 -pix_fmt yuv420p "$TMP_VIDEO" -y

# 3. Combine voice + video
ffmpeg -i "$TMP_VIDEO" -i "$TMP_WAV" -c:v copy -c:a aac -shortest "$OUTFILE" -y

# Cleanup
rm -f "$TMP_WAV" "$TMP_VIDEO"

echo "✅ Done! → ${OUTFILE}"
echo "Upload this to the website with the ciphertext text below it."

