Last active
August 1, 2020 06:24
-
-
Save meesix/82e749de38663688e98d990a1cdcf57e to your computer and use it in GitHub Desktop.
Convert ZOOM chat log to SRT subtitle
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
#!/usr/bin/env python | |
''' | |
Simple script to convert ZOOM chat log to SRT subtitle | |
USAGE: conver.py FILE | |
Outputs subtitle data to stdout | |
''' | |
import datetime | |
import sys | |
def main(): | |
filename = sys.argv[-1] | |
f = open(filename, "r") | |
prev_time = None | |
subs = [] | |
for line in f: | |
chunks = line.split(' ') | |
time = datetime.datetime.strptime(chunks[0], '%H:%M:%S') | |
text = chunks[1].split(" : ")[-1] | |
if prev_time is not None: | |
difference = time - prev_time | |
hours, _ = divmod(difference.seconds, 3600) | |
minutes, seconds = divmod(difference.seconds, 60) | |
subs.append({'time':'{:02}:{:02}:{:02},000'.format(int(hours), int(minutes), int(seconds)), 'text':text}) | |
else: | |
prev_time = time | |
subs.append({'time':'00:00:00,000', 'text':text}) | |
f.close() | |
for i in range(len(subs)): | |
print("{} \n".format(i + 1)) | |
start_time = end_time = subs[i]['time'] | |
if (i<len(subs)-1): | |
end_time = subs[i + 1]['time'] | |
print("{} --> {}\n".format(start_time, end_time)) | |
print(subs[i]['text'].replace('\r', '')) | |
print("\n") | |
if __name__ == "__main__": | |
if (len(sys.argv) < 2): | |
print("\n") | |
print("ZOOM chat log to SRT converter") | |
print("Usage: convert.py FILE \n") | |
sys.exit(-1) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are the life saver!!! I’ve been looking for this script whole my life!!!