summaryrefslogtreecommitdiffstats
path: root/.local/bin/srt-normalise
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2025-02-13 14:13:49 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2025-02-13 14:13:49 +0530
commit8a2e1006b3b272126332aa064f3ad95387129544 (patch)
tree944c80ac612a65980d94a54ba11b6c7102037ecf /.local/bin/srt-normalise
parentdcbb16d8b08ff5956abef5e6478b59df2e93ad35 (diff)
downloaddotfiles-8a2e1006b3b272126332aa064f3ad95387129544.tar.gz
dotfiles-8a2e1006b3b272126332aa064f3ad95387129544.tar.bz2
dotfiles-8a2e1006b3b272126332aa064f3ad95387129544.zip
new dot filesHEADmaster
Diffstat (limited to '.local/bin/srt-normalise')
-rwxr-xr-x.local/bin/srt-normalise28
1 files changed, 28 insertions, 0 deletions
diff --git a/.local/bin/srt-normalise b/.local/bin/srt-normalise
new file mode 100755
index 0000000..51461ce
--- /dev/null
+++ b/.local/bin/srt-normalise
@@ -0,0 +1,28 @@
+#!/usr/local/bin/python3
+
+"""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()