#!/bin/bash
# Rendareza un proiect HyperFrames la MP4.
# Proiectele sunt in ~/videos/<nume-proiect>/index.html
# Output-ul merge in acelasi director, accesibil la:
#   https://moltbot.tailf7372d.ts.net/echo/videos/<proiect>/output.mp4
#
# Utilizare:
#   ./hyperframes_render.sh <director-proiect> [output.mp4]
#   ./hyperframes_render.sh ~/videos/obs-vs-interpretare
#   ./hyperframes_render.sh ~/videos/obs-vs-interpretare final.mp4
#
# Fix LXC: HyperFrames foloseste pipe in loc de TCP (seccomp blocheaza socket)
# si chrome-headless-shell din cache-ul Playwright.

set -e

CHROME="/home/moltbot/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell"
PROJECT_DIR="${1:?Utilizare: $0 <director-proiect> [output.mp4]}"
OUTPUT="${2:-output.mp4}"

if [ ! -f "$PROJECT_DIR/index.html" ]; then
  echo "Eroare: nu gasesc $PROJECT_DIR/index.html"
  exit 1
fi

export PATH="/home/moltbot/bin:$PATH"
export HYPERFRAMES_BROWSER_PATH="$CHROME"

cd "$PROJECT_DIR"
npx hyperframes render --output "$OUTPUT" --fps 30 --quality standard

echo ""
echo "Video randat: $PROJECT_DIR/$OUTPUT"
RELPATH="${PROJECT_DIR#/home/moltbot/videos/}"
echo "Link: https://moltbot.tailf7372d.ts.net/echo/videos/$RELPATH/$OUTPUT"
