import sys
import re
from google.colab import files
temp = sys.stdout
with open("out.txt", mode='r',encoding='utf-8') as f:
lines = f.readlines()
sys.stdout = open('subtitles.srt', 'w+')
counter = 0
for ind,line in enumerate(lines):
#[00:00.000 --> 00:04.320]
if (timecode := re.findall(r'\[(.+?)\]\s', line)):
counter += 1
print(counter)
if (ch1 := re.findall(r'\d+\:\d+\:\d+\.\d+',timecode[0])):
print(timecode[0].replace('.', ','))
else:
if (ch2 := re.findall(r'\d+\:\d+\.\d+',timecode[0])):
print("00:" + ch2[0].replace('.', ','),end="")
print(" --> 00:" + ch2[1].replace('.', ','))
# print(timecode[0].replace('.', ','))
if (dropdown == "ja"):
if (strings := re.findall(r'.+?\]\s(\S*?)$', line)):
print(strings[0])
print()
else:
if (strings := re.findall(r'.+?\]\s\s(.*?)$', line)):
print(strings[0])
print()
sys.stdout.close()
sys.stdout = sys.__stdout__
files.download('subtitles.srt')