aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 7b5cea3ab32ce2eb2de087e988330f25350811a7 (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
49
50
51
# 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

```python
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:
    # Make every event start and end a second later
    event.start.second += 1
    event.end.second += 1
    # Capitalize all the displayed text
    event.content = event.content.upper()

# 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
- [x] Parse timecodes into their numeric components
- [ ] More filters? As and when use-cases emerge