Parse SRT subtitle files into structured JSON format, supporting extraction of timecodes, calculation of duration, and generation of statistics.
Quick Start
Basic Usage
# 解析 SRT 文件,输出到终端
python <skill_path>/scripts/parse_srt.py input.srt
# 输出到文件
python <skill_path>/scripts/parse_srt.py input.srt -o output.json
# 包含统计信息
python <skill_path>/scripts/parse_srt.py input.srt --stats
Output plain text only (remove timecodes)
python <skill_path>/scripts/parse_srt.py input.srt --text-only
**注意:** `<skill_path>` 是此 skill 的安装路径,通常为 `~/.claude/plugins/srt-to-structured-data@claude-code-skills/skills/srt-to-structured-data`
## 输出格式
### JSON 结构化数据
```json
{
"subtitles": [
{
"index": 1,
"start_time": "00:00:00,000",
"end_time": "00:00:02,566",
"start_ms": 0,
"end_ms": 2566,
"duration_ms": 2566,
"text": "Clawdbot真的太火太火太火了"
},
{
"index": 2,
"start_time": "00:00:02,633",
"end_time": "00:00:04,766",
"start_ms": 2633,
"end_ms": 4766,
"duration_ms": 2133,
"text": "Github一天直接涨了5万星"
}
],
"statistics": {
"total_count": 2,
"total_duration_ms": 4699,
"total_duration_formatted": "00:04",
"avg_duration_ms": 2349
}
}
Plain text output
When using the --text-only parameter, only subtitle text is output, one line per entry:
Clawdbot真的太火太火太火了
Github一天直接涨了5万星
Command-line arguments
| Argument | Description |
|---|---|
input.srt |
Path to the input SRT subtitle file |
-o, --output |
Output file path (defaults to output to the terminal) |
--stats |
Include statistics in the JSON output |
--text-only |
Output plain text only, removing timecodes and sequence numbers |
Field descriptions
| Field | Type | Description |
|---|---|---|
index |
int | Subtitle sequence number |
start_time |
string | Start time (original format) |
end_time |
string | End time (original format) |
start_ms |
int | Start time (milliseconds) |
end_ms |
int | End time (milliseconds) |
duration_ms |
int | Duration (milliseconds) |
text |
string | Subtitle text content |
Usage examples
Scenario 1: Analyze a subtitle file
python <skill_path>/scripts/parse_srt.py video.srt --stats -o analysis.json
Scenario 2: Extract plain text for translation
python <skill_path>/scripts/parse_srt.py video.srt --text-only -o transcript.txt
Scenario 3: Use directly in Python
import subprocess
import json
result = subprocess.run(
['python', '<skill_path>/scripts/parse_srt.py',
'input.srt', '--stats'],
capture_output=True, text=True
)
data = json.loads(result.stdout)