Created
April 2, 2020 00:36
-
-
Save berndverst/1fbf920dda649e2d6ba1e68f1649b924 to your computer and use it in GitHub Desktop.
Convert Subtitles in WebVTT format exported from Microsoft Stream to SRT
This file contains 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
# Conversion of Microsoft Stream WebVTT file to SRT | |
# Takes advantage of specific metadata structure in Microsoft Stream VTT files | |
vtt = open('INPUT.vtt','r') | |
vtt_iter = iter(vtt) | |
with open('OUTPUT.srt', 'w') as srt: | |
counter = 1 | |
next(vtt_iter) | |
for line in vtt_iter: | |
if line.startswith('NOTE Confidence'): | |
srt.write('\n' + str(counter) + '\n') | |
counter+=1 | |
next(vtt_iter) | |
next(vtt_iter) | |
timewindow = next(vtt_iter) | |
timewindow = timewindow.replace('.',',').rstrip('\r\n') | |
srt.write(timewindow + '\n') | |
else: | |
if line.startswith('NOTE') or line.rstrip('\r\n') == '': | |
continue | |
else: | |
srt.write(line.rstrip('\r\n') + '\n') | |
vtt.close() | |
srt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment