Crates.io | srt2txt |
lib.rs | srt2txt |
version | 0.1.1 |
created_at | 2025-08-20 12:39:07.432663+00 |
updated_at | 2025-08-21 18:41:36.481608+00 |
description | Convert SRT subtitle files into clean plain text (strip timestamps, tags, merge lines) |
homepage | https://github.com/chrisdoc/srt2txt |
repository | https://github.com/chrisdoc/srt2txt |
max_upload_size | |
id | 1803344 |
size | 38,088 |
Convert SRT subtitle files into clean plain text. Fast & parallel with safe defaults and composable post‑processing.
<i>
, <b>
, etc.)--join
) OR flatten all captions into one sentence stream (--join-sentences
)--force
cargo install srt2txt
# Basic conversion (creates input.txt next to input.srt)
srt2txt input.srt
# Convert a directory tree recursively → outputs into cleaned/
srt2txt subtitles/ --output-dir cleaned/
# Join several files into combined.txt (default name)
srt2txt a.srt b.srt --join
# Custom join filename
srt2txt a.srt b.srt --join --join-name all_dialogue.txt
# Stream per‑file results to stdout (no files written)
srt2txt movie.srt --stdout
# Single continuous text block (no blank separators)
srt2txt movie.srt --join-sentences --stdout
Input (sample.srt
):
1
00:00:00,000 --> 00:00:01,000
<i>Hello</i> world!
2
00:00:01,500 --> 00:00:03,000
Second line.
Line continued.
Output (sample.txt
):
Hello world!
Second line. Line continued.
--stdout Print combined per-file outputs to stdout (disables file writes)
--join Aggregate all processed files into a single output (excludes --stdout, --join-sentences)
--join-name <NAME> Filename for --join output (default: combined.txt)
--join-sentences Flatten all captions into one continuous block (ignores --collapse-blank; conflicts with --join)
--collapse-blank Collapse ≥3 consecutive newlines to a single blank line
--remove-duplicates Remove immediately repeated normalized lines
-f, --force Overwrite existing output files
-o, --output-dir DIR Directory for outputs (created if missing)
Combination | Allowed | Notes |
---|---|---|
--stdout + --join |
❌ | Mutually exclusive |
--join + --join-sentences |
❌ | Different aggregation semantics |
--join-sentences + --collapse-blank |
⚠️ | Runs; blank collapse skipped (warning emitted) |
Existing output & no --force |
❌ | Aborts to prevent overwrite |
.srt
files ignored; directories walked recursively.<[^>]+>
): removes any simple tag.lazy_static
.Core logic resides in src/main.rs
(parsing, cleaning, post-process, CLI validation).
Build & test locally:
cargo build
cargo test --all --quiet
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
Installed/updated on cargo build
according to Cargo.toml
:
Hook | Command(s) |
---|---|
pre-commit | cargo fmt --all -- --check then cargo clippy --all-targets --all-features -- -D warnings |
pre-push | cargo test --all --quiet |
Skip temporarily:
HUSKY=0 git commit -m "wip"
Force regenerate if stale:
cargo clean -p cargo-husky || true
cargo build
Keep features lean. Add unit tests beside changed logic (see existing tests in src/main.rs
). Maintain flag validation in main
. When modularizing, prefer pure helpers (e.g. parser.rs
, transform.rs
) while preserving existing behavior.
MIT