Skip to content

Instantly share code, notes, and snippets.

@pshchelo
Created February 6, 2017 16:47
Show Gist options
  • Save pshchelo/7b311357ab0c49a0bc4d467c2a75a745 to your computer and use it in GitHub Desktop.
Save pshchelo/7b311357ab0c49a0bc4d467c2a75a745 to your computer and use it in GitHub Desktop.
convert SubRip subtitles to WebVTT (suitable for WebM format)
#!/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