Conversion_Kitchen_Code/kitchen_counter/conversion/subtitling/TestingburnNew.py

69 lines
1.8 KiB
Python
Raw Permalink Normal View History

2024-04-27 09:33:09 +00:00
import pysrt
from pysubparser import parser
import datetime
from datetime import datetime
import time
from itertools import groupby
#subtitles = parser.parse("/home/user/mnf/project/MNF/media/videos/Subtitling_Videos/german/azure_subtitle.srt")
srt_data = pysrt.open("/home/user/mnf/project/MNF/media/videos/Subtitling_Videos/german/azure_subtitle.srt")
#print(srt_data)
subs = []
for i in srt_data:
if i.start.minutes == 0:
text = i.text
start = i.start.seconds
end = i.end.seconds
#print(type(start))
subs.append(((start, end), text))
else:
text = i.text
start_s = i.start.seconds
print(type(start_s))
start_m = i.start.minutes
start = str(start_m) + "." + str(start_s)
start = start_m + start_s/60
print(type(start))
end_s = i.end.seconds
end_m = i.end.minutes
end = end_m + end_s/60
print(type(start))
subs.append(((float(start), float(end)), text))
print(subs)
"""
with open("/home/user/mnf/project/MNF/media/videos/Subtitling_Videos/german/azure_subtitle.srt") as f:
res = [list(g) for b,g in groupby(f, lambda x: bool(x.strip())) if b]
#print(res)
from collections import namedtuple
Subtitle = namedtuple('Subtitle', 'number start end content')
subs = []
texting_list = []
for sub in res:
if len(sub) >= 3: # not strictly necessary, but better safe than sorry
sub = [x.strip() for x in sub]
number, start_end, *content = sub # py3 syntax
start, end = start_end.split(' --> ')
start_1 = start.split(',')[0]
end_1 = end.split(',')[0]
start = start_1
end = end_1
start_n = time.strptime(start,"%H:%M:%S")
end_n = time.strptime(end,"%H:%M:%S")
texting_list.append(((start_n,end_n), content[0]))
subs.append(Subtitle(number, start, end, content))
print(texting_list)
"""