Fix
This commit is contained in:
parent
c169bff624
commit
f5f9238161
40
vttmaker.py
40
vttmaker.py
|
@ -101,6 +101,7 @@ def on_done_press(event = None):
|
||||||
if current_subtitle["start"] != None:
|
if current_subtitle["start"] != None:
|
||||||
mark_end()
|
mark_end()
|
||||||
subtitles.append({"start": None,"end": None,"content": None,"split": True})
|
subtitles.append({"start": None,"end": None,"content": None,"split": True})
|
||||||
|
scene_breaks.append(line_index)
|
||||||
update_display()
|
update_display()
|
||||||
|
|
||||||
def on_back(event = None):
|
def on_back(event = None):
|
||||||
|
@ -158,29 +159,42 @@ def update_display():
|
||||||
subtitle_text.config(state=tk.NORMAL)
|
subtitle_text.config(state=tk.NORMAL)
|
||||||
subtitle_text.delete("1.0", tk.END)
|
subtitle_text.delete("1.0", tk.END)
|
||||||
|
|
||||||
for n, line in enumerate(script_lines):
|
scene_breaks = []
|
||||||
display_line = " " + line
|
real_index = 0
|
||||||
script_listbox.insert(tk.END, display_line)
|
for n in range(len(subtitles)):
|
||||||
# print(n, len(subtitles))
|
|
||||||
if n < len(subtitles):
|
if n < len(subtitles):
|
||||||
lstart = subtitles[n]["start"]
|
lstart = subtitles[n]["start"]
|
||||||
lend = subtitles[n]["end"]
|
lend = subtitles[n]["end"]
|
||||||
if lstart:
|
if lstart:
|
||||||
subtitle_display = f"{n+1}\n{to_time(lstart)} --> {to_time(lend)}\n{multiline(subtitles[n]['content']).replace("\n", "↵\n")} \n\n"
|
subtitle_display = f"{subtitles[n]["index"]}\n{to_time(lstart)} --> {to_time(lend)}\n{multiline(subtitles[n]['content']).replace("\n", "↵\n")} \n\n"
|
||||||
else:
|
else:
|
||||||
|
scene_breaks.append(subtitles[n-1]["index"])
|
||||||
|
print(f"End section at idx {subtitles[n-1]["index"]}, {to_time(subtitles[n-1]["end"])}")
|
||||||
subtitle_display = f"----------\n\n"
|
subtitle_display = f"----------\n\n"
|
||||||
subtitle_text.insert(tk.END, subtitle_display)
|
subtitle_text.insert(tk.END, subtitle_display)
|
||||||
|
|
||||||
elif n == len(subtitles) :
|
elif n == len(subtitles) :
|
||||||
lstart = current_subtitle.get("start", "")
|
lstart = current_subtitle.get("start", "")
|
||||||
|
|
||||||
if lstart:
|
if lstart:
|
||||||
subtitle_display = f"{n+1}\n{to_time(lstart)} -> \n{multiline(current_subtitle.get('content'))} \n\n"
|
subtitle_display = f"{subtitles[n]["index"]}\n{to_time(lstart)} -> \n{multiline(current_subtitle.get('content').replace("\n", "↵\n"))} \n\n"
|
||||||
subtitle_text.insert(tk.END, subtitle_display)
|
subtitle_text.insert(tk.END, subtitle_display)
|
||||||
|
|
||||||
|
list_color = 0
|
||||||
|
for n, line in enumerate(script_lines):
|
||||||
|
display_line = " " + line
|
||||||
|
script_listbox.insert(tk.END, f"{n:03} " + display_line)
|
||||||
|
if n-1 in scene_breaks:
|
||||||
|
print(f"New section from {n}")
|
||||||
|
list_color = ~list_color
|
||||||
if n == line_index:
|
if n == line_index:
|
||||||
script_listbox.itemconfig(n, {'bg': 'lightgrey'})
|
script_listbox.itemconfig(n, {'bg': 'lightgrey'})
|
||||||
|
|
||||||
|
if n < line_index:
|
||||||
|
if list_color:
|
||||||
|
script_listbox.itemconfig(n, {'bg': '#FFEFFF'})
|
||||||
|
else:
|
||||||
|
script_listbox.itemconfig(n, {'bg': '#FFFFEF'})
|
||||||
|
|
||||||
if player.is_playing() or not audio_started:
|
if player.is_playing() or not audio_started:
|
||||||
script_listbox.see(min(line_index + 5, len(script_lines)))
|
script_listbox.see(min(line_index + 5, len(script_lines)))
|
||||||
subtitle_text.see(tk.END)
|
subtitle_text.see(tk.END)
|
||||||
|
@ -252,18 +266,24 @@ def save_stacked_subtitles():
|
||||||
vtt_path = filedialog.asksaveasfilename(defaultextension=".vtt", filetypes=[("VTT files", "*.vtt"), ("All files", "*.*")])
|
vtt_path = filedialog.asksaveasfilename(defaultextension=".vtt", filetypes=[("VTT files", "*.vtt"), ("All files", "*.*")])
|
||||||
if vtt_path:
|
if vtt_path:
|
||||||
with open(vtt_path, 'w') as f:
|
with open(vtt_path, 'w') as f:
|
||||||
f.write('WEBVTT\n\n')
|
f.write('WEBVTT\n\n\n')
|
||||||
buffer = ""
|
buffer = ""
|
||||||
for subtitle in subtitles:
|
for subtitle in subtitles:
|
||||||
if subtitle.get("break", False):
|
if subtitle.get("split", False):
|
||||||
buffer = ""
|
buffer = ""
|
||||||
|
continue
|
||||||
|
|
||||||
if len(buffer) != 0:
|
if len(buffer) != 0:
|
||||||
|
if str(subtitle['content'].strip())[-1] == ".":
|
||||||
buffer += "\n"
|
buffer += "\n"
|
||||||
|
else:
|
||||||
|
buffer += " "
|
||||||
|
|
||||||
buffer += multiline(subtitle['content'])
|
buffer += multiline(subtitle['content'])
|
||||||
|
|
||||||
f.write(f"{to_time(subtitle['start'])} --> {to_time(subtitle['end'])}\n")
|
f.write(f"{to_time(subtitle['start'])} --> {to_time(subtitle['end'])}\n")
|
||||||
f.write(buffer)
|
f.write(buffer)
|
||||||
f.write("\n\n")
|
f.write("\n\n\n")
|
||||||
|
|
||||||
print(f"Done saving {len(subtitles)} subtitles (stacking)")
|
print(f"Done saving {len(subtitles)} subtitles (stacking)")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue