3 个版本 (破坏性更新)
0.3.0 | 2020 年 5 月 29 日 |
---|---|
0.2.0 | 2020 年 5 月 28 日 |
0.1.0 | 2020 年 5 月 28 日 |
#8 在 #first-line
19KB
307 行
subfilter
命令行工具,用于处理和过滤字幕文件中的内容。
我使用它从字幕文件中获取预处理后的清洁输出。这个工具类似于 grep
或 rip-grep
等,但了解字幕文件格式。在这个工具的上下文中,“行”等同于完整的字幕条目(可能包含多个换行符)。您还可以请求打印与匹配行有持续时间差异的上下文行。
用法
subfilter [FLAGS] [OPTIONS] <file-path> [pattern]
FLAGS:
-h, --help Prints help information
--hide-time Whether timecode should be shown for the first line
--no-color Disable color output for matching part
-V, --version Prints version information
-v, --verbose Verbose output
OPTIONS:
-A, --after-context <after-context> Number of lines to show after each match [default: 0]
-C, --context <around-context>
Number of lines to show before and after each match. This overrides both the -B/--before-context and
-A/--after-context flags
-B, --before-context <before-context> Number of lines to show after each match [default: 0]
--post-replace-pattern <post-replace-pattern>
Pattern to replace after pattern matching (see https://docs.rs/regex/1.3.7/regex/)
--post-replace-with <post-replace-with>
Replacement string after pattern matching (see https://docs.rs/regex/1.3.7/regex/)
--pre-replace-pattern <pre-replace-pattern>
Pattern to replace before pattern matching (see https://docs.rs/regex/1.3.7/regex/)
--pre-replace-with <pre-replace-with>
Replacement string before pattern matching (see https://docs.rs/regex/1.3.7/regex/)
-i, --sep-interval <separation-interval-ms>
Separate blocks if next timecode is later by an offset of this value in milliseconds [default: 5000]
--time-after <time-after-context>
Duration threshold in milliseconds to decide whether we show a line after a match. This overrides
-C/--context -B/--before-context and -A/--after-context flags
--time-around <time-around-context>
Duration threshold in milliseconds to decide whether we show a line around a match. This overrides --time-
after, --time-before, -C/--context -B/--before-context and -A/--after-context flags
--time-before <time-before-context>
Duration threshold in milliseconds to decide whether we show a line before a match. This overrides
-C/--context -B/--before-context and -A/--after-context flags
ARGS:
<file-path> Input file
<pattern> Pattern to find (see https://docs.rs/regex/1.3.7/regex/)
演示
基本用法
带有一些正则表达式预处理步骤
示例
打印所有包含 "hello" 的行
subfilter subs.srt hello
打印所有包含 "hello" 或 "hi" 的行
subfilter subs.ass "(hello|hi")"
打印包含 "hello" 的行,同时显示前一行和下一行作为上下文。
subfilter -A 10 -B 1 subs.ass hello
打印包含 "hello world" 的所有行,但在应用匹配和替换正则表达式之前先删除 HTML 标签。这样,<span>hello</span> world
也会被过滤模式匹配。
subfilter --pre-replace-pattern="<\s*[\.a-zA-Z]+[^>]*>(.*?)<\s*/\s*[\.a-zA-Z]+>" --pre-replace-with="\$1" subs.ass "hello world"
打印包含 "hello world" 的所有行,但将 "hello" 替换为 "hi"。
subfilter --post-replace-pattern="hello" --post-replace-with="hi" subs.srt "hello world"
安装
- 安装 Rust 工具链
- 运行以下命令下载和编译
$ cargo install subfilter
依赖项
~15–26MB
~441K SLoC