Created
February 9, 2024 15:46
-
-
Save neckro/95a3050b8782c600ec390037c3ae7301 to your computer and use it in GitHub Desktop.
convert faster-whisper subs to an actually usable format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import fileinput | |
import re | |
from math import floor | |
def main(): | |
r = re.compile("(\\d+\\.\\d+) --> (\\d+\\.\\d+)") | |
for line in fileinput.input(): | |
m = r.match(line) | |
if m is None: | |
print (line.rstrip()) | |
else: | |
# print (line.rstrip()) | |
print ("%s --> %s" % (convtime(m.group(1)), convtime(m.group(2)))) | |
def convtime(i): | |
i = float (i) | |
h = floor (i / 3600) | |
i = i - (3600 * h) | |
m = floor (i / 60) | |
i = i - (60 * m) | |
s = floor (i) | |
frag = str(round(i - s, 3)).lstrip("0").lstrip(".") | |
# print("h:", h) | |
# print("m:", m) | |
# print("s:", s) | |
# print("frag:", frag) | |
return "%s:%s:%s,%s" % (pad(h), pad(m), pad(s), frag) | |
def pad(n): | |
if (n < 10): | |
return "0%s" % n | |
return n | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment