Created
February 6, 2017 16:47
-
-
Save pshchelo/7b311357ab0c49a0bc4d467c2a75a745 to your computer and use it in GitHub Desktop.
convert SubRip subtitles to WebVTT (suitable for WebM 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 python | |
import sys | |
import re | |
with open(sys.argv[1], 'r') as infile: | |
data = infile.readlines() | |
timecodere = re.compile("^\d*:\d\d:\d\d,\d\d\d --> \d*:\d\d:\d\d,\d\d\d") | |
outdata = [] | |
for line in data: | |
if timecodere.match(line): | |
outdata.append(line.replace(",", ".")) | |
else: | |
outdata.append(line) | |
with open(sys.argv[1] + ".vtt", 'w') as outfile: | |
outfile.write("WEBVTT\n\n") | |
outfile.writelines(outdata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment