Skip to content

Instantly share code, notes, and snippets.

@meesix
Created July 31, 2020 22:32
Show Gist options
  • Save meesix/dda57370dabe2efb79b6d827c71a8850 to your computer and use it in GitHub Desktop.
Save meesix/dda57370dabe2efb79b6d827c71a8850 to your computer and use it in GitHub Desktop.
Convert ZOOM chat log to SRT subtitle
import datetime
f = open("chat.txt", "r")
prev_time = None
subs = []
for x in f:
chunks = x.split(' -> ');
time = datetime.datetime.strptime(chunks[0], '%H:%M:%S')
if prev_time is not None:
difference = time - prev_time
hours, remainder = 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':chunks[1]})
else:
prev_time = time
f.close();
f = open("chat.srt", "w")
for i in range(len(subs)-1):
f.write("{} \n".format(i))
f.write("{} --> {}\n".format(subs[i]['time'], subs[i+1]['time']))
f.write(subs[i]['text'].replace('\r', ''))
f.write("\n")
f.close()
#!/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 x in f:
chunks = x.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