forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

seed.sh37 lines, 1.5 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# seed.sh: fill fuzz/corpus/<target>/ from the repo's ASS fixture.
3#
4# fixtures/subs/real.ass seeds script whole. events and overrides get its Dialogue rows (the lines
5# after the first Dialogue: prefix, which is what each of those targets takes as input). styles gets
6# the Style rows. Corpus lives under fuzz/corpus, git-ignored.
7set -euo pipefail
8
9FUZZ_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
10ROOT=$(cd -- "$FUZZ_DIR/../../.." && pwd)
11SUBS="$ROOT/fixtures/subs"
12[ -d "$SUBS" ] || { echo "seed.sh: $SUBS missing; run scripts/link-fixtures.sh" >&2; exit 2; }
13
14CORPUS="$FUZZ_DIR/corpus"
15mkdir -p "$CORPUS"/{script,styles,events,overrides}
16
17python3 -I - "$SUBS/real.ass" "$CORPUS" <<'PY'
18import os, sys
19
20ass, corpus = sys.argv[1], sys.argv[2]
21data = open(ass, "rb").read()
22lines = data.decode("utf-8", "replace").splitlines(keepends=True)
23dialogue = [l.split(":", 1)[1].lstrip() for l in lines if l.startswith("Dialogue:")]
24styles = [l.split(":", 1)[1].lstrip() for l in lines if l.startswith("Style:")]
25
26def write(path, body):
27 with open(path, "wb") as f:
28 f.write(body)
29
30write(os.path.join(corpus, "script", "real.ass"), data)
31for i, row in enumerate(dialogue[:400]):
32 write(os.path.join(corpus, "events", f"row{i:04}"), row.encode())
33 write(os.path.join(corpus, "overrides", f"row{i:04}"), b"\x00" + row.encode())
34for i, row in enumerate(styles[:200]):
35 write(os.path.join(corpus, "styles", f"row{i:04}"), b"\x00" + row.encode())
36print(f"ec-ass seeds: {len(dialogue)} dialogue rows, {len(styles)} style rows")
37PY