File: srt-normalise

package info (click to toggle)
python-srt 3.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 236 kB
  • sloc: python: 1,599; makefile: 13
file content (28 lines) | stat: -rwxr-xr-x 790 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

"""Takes a badly formatted SRT file and outputs a strictly valid one."""

import srt_tools.utils
import logging

log = logging.getLogger(__name__)


def main():
    examples = {"Normalise a subtitle": "srt normalise -i bad.srt -o good.srt"}

    args = srt_tools.utils.basic_parser(
        description=__doc__, examples=examples, hide_no_strict=True
    ).parse_args()
    logging.basicConfig(level=args.log_level)
    srt_tools.utils.set_basic_args(args)
    output = srt_tools.utils.compose_suggest_on_fail(args.input, strict=args.strict)

    try:
        args.output.write(output)
    except (UnicodeEncodeError, TypeError):  # Python 2 fallback
        args.output.write(output.encode(args.encoding))


if __name__ == "__main__":  # pragma: no cover
    main()