#!/usr/bin/env bash set -Eeuo pipefail source "$(cd -- "$(dirname -- "$0")" && pwd)/common.sh" need docker output_file="$REPO_ROOT/captions.txt" temp_file="$(mktemp "$REPO_ROOT/.captions.txt.XXXXXX")" trap 'rm -f -- "$temp_file"' EXIT # Export from the canonical SQLite database. The newer contact-sheet captions # live in caption_windows, while older per-frame captions live in frames. # Write to a temporary file so a Docker/SQL failure cannot truncate a # previously successful export. compose exec -T scene-search python - <<'PY' > "$temp_file" import sqlite3 con = sqlite3.connect("/app/data/scenes.sqlite3") con.row_factory = sqlite3.Row try: rows = con.execute(""" SELECT m.title, m.jellyfin_item_id, cw.start_ms AS timestamp_ms, cw.caption FROM caption_windows cw JOIN media m ON m.id = cw.media_id WHERE cw.caption IS NOT NULL AND TRIM(cw.caption) != '' UNION ALL SELECT m.title, m.jellyfin_item_id, f.timestamp_ms, f.caption FROM frames f JOIN media m ON m.id = f.media_id WHERE f.caption IS NOT NULL AND TRIM(f.caption) != '' ORDER BY title, timestamp_ms """) for row in rows: seconds = int(row["timestamp_ms"]) // 1000 hours, remainder = divmod(seconds, 3600) minutes, seconds = divmod(remainder, 60) timestamp = f"{hours:02d}:{minutes:02d}:{seconds:02d}" caption = " ".join(row["caption"].split()) print(f"{row['title']} [{timestamp}]") print(f"Jellyfin ID: {row['jellyfin_item_id']}") print(f"Caption: {caption}") print() finally: con.close() PY mv -f -- "$temp_file" "$output_file" printf 'Saved all captions to %s\n' "$output_file"