aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 1c6e9e532eb915917d8980f2edce02da6709149e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# srtfilter

Parser for SubRip (SRT) subtitle format and framework for utilities that manipulate it.

Install from PyPI: [`srtfilter`](https://pypi.org/project/srtfilter/).

## Usage

### CLI tool

Parse and reproduce an SRT file (output goes to stdout):

`srtfilter input.srt`

Break lines automatically (to handle existing files with poor line breaks):

`srtfilter --filter rebreak_lines input.srt`

More filters can be added in the `src/srtfilter/filters` directory.

### Library

```
import srtfilter.parse as srtparse
import sys

with open("input.srt") as f:
    srt = srtparse.SRT.from_str(f.read())

for event in srt.events:
    print(event.start, event.end, event.content)
    event.content = event.content.upper() # for example

# srt.__str__() produces a valid SRT file from the parsed representation
sys.stdout.write(str(srt))
```

## License

MIT License; see `LICENSE.txt`.

## Roadmap

- [x] Parse SRT
- [x] Make CLI tool modular
- [x] Add filter for breaking lines
- [ ] Parse timecodes and allow arithmetic with them
- [ ] More filters? As and when use-cases emerge