|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 5 | +cd "$ROOT_DIR" |
| 6 | + |
| 7 | +# Pure parsing coverage via --dry-run: no ffmpeg or real media required. |
| 8 | + |
| 9 | +TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/podguy-cut-parse-test.XXXXXX")" |
| 10 | +trap 'rm -rf "$TMP_DIR"' EXIT |
| 11 | + |
| 12 | +media="$TMP_DIR/source with spaces.mp4" |
| 13 | +printf 'fake media bytes' >"$media" |
| 14 | + |
| 15 | +# Markdown with mixed range separators, fractional seconds, and a duplicate. |
| 16 | +cat >"$TMP_DIR/clips.md" <<'EOF' |
| 17 | +# Clip candidates |
| 18 | +
|
| 19 | +## Arrow separator |
| 20 | +- 00:00:01 --> 00:00:03 — arrow range |
| 21 | +
|
| 22 | +## Dash separator |
| 23 | +- 00:01:12.5 - 00:02:03 — fractional start |
| 24 | +
|
| 25 | +## Word separator |
| 26 | +- 00:03:00 to 00:03:30 — word range |
| 27 | +
|
| 28 | +## Duplicate of the arrow range |
| 29 | +- 00:00:01 - 00:00:03 — should be deduped |
| 30 | +EOF |
| 31 | + |
| 32 | +uv run python scripts/cut_clips.py "$media" "$TMP_DIR/clips.md" "$TMP_DIR/md" --dry-run >/dev/null |
| 33 | + |
| 34 | +cat >"$TMP_DIR/clips.json" <<'EOF' |
| 35 | +{ |
| 36 | + "clips": [ |
| 37 | + { "title": "JSON clip", "start": "00:00:05", "end": "00:00:09" } |
| 38 | + ] |
| 39 | +} |
| 40 | +EOF |
| 41 | + |
| 42 | +uv run python scripts/cut_clips.py "$media" "$TMP_DIR/clips.json" "$TMP_DIR/json" --dry-run >/dev/null |
| 43 | + |
| 44 | +cat >"$TMP_DIR/clips.csv" <<'EOF' |
| 45 | +title,start,end |
| 46 | +CSV clip,00:00:10,00:00:14 |
| 47 | +EOF |
| 48 | + |
| 49 | +uv run python scripts/cut_clips.py "$media" "$TMP_DIR/clips.csv" "$TMP_DIR/csv" --dry-run >/dev/null |
| 50 | + |
| 51 | +uv run python - "$TMP_DIR" <<'PY' |
| 52 | +import json |
| 53 | +import sys |
| 54 | +from pathlib import Path |
| 55 | +
|
| 56 | +tmp = Path(sys.argv[1]) |
| 57 | +
|
| 58 | +md = json.loads((tmp / "md" / "manifest.json").read_text()) |
| 59 | +clips = md["clips"] |
| 60 | +assert len(clips) == 3, f"expected 3 deduped markdown clips, got {len(clips)}" |
| 61 | +starts = [clip["start"] for clip in clips] |
| 62 | +assert starts == [1.0, 72.5, 180.0], starts |
| 63 | +assert clips[1]["end"] == 123.0, clips[1] |
| 64 | +
|
| 65 | +js = json.loads((tmp / "json" / "manifest.json").read_text()) |
| 66 | +assert len(js["clips"]) == 1 |
| 67 | +assert js["clips"][0]["start"] == 5.0 |
| 68 | +assert js["clips"][0]["title"] == "JSON clip" |
| 69 | +
|
| 70 | +csv = json.loads((tmp / "csv" / "manifest.json").read_text()) |
| 71 | +assert len(csv["clips"]) == 1 |
| 72 | +assert csv["clips"][0]["start"] == 10.0 |
| 73 | +assert csv["clips"][0]["end"] == 14.0 |
| 74 | +
|
| 75 | +# The dry-run command list must keep the spaced media path as one argument. |
| 76 | +assert any("source with spaces.mp4" in part for part in md["clips"][0]["command"]) |
| 77 | +
|
| 78 | +print("cut_clips parsing assertions passed") |
| 79 | +PY |
| 80 | + |
| 81 | +echo "ok: cut_clips parsing smoke test passed" |
0 commit comments