Skip to content
Extraits de code Groupes Projets
Valider 15fdd0bc rédigé par Sting's avatar Sting
Parcourir les fichiers

Retrieve header+template from reference file

parent c3d5164c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!4Lyrics Alignment
......@@ -5,7 +5,7 @@ import subprocess
import shlex
from pathlib import Path
from autosyl.assUtils import AssWriter, getSyls
from autosyl.assUtils import AssWriter, getSyls, getHeader
from autosyl.segment import segment
......@@ -52,7 +52,7 @@ print(syls)
print("Syls found, writing ASS file...")
writer = AssWriter()
writer.openAss(ass_file)
writer.writeHeader()
writer.writeHeader(header=getHeader(reference_file))
writer.writeSyls(syls)
writer.closeAss()
......@@ -41,6 +41,20 @@ def getSyls(ass_file):
return SYLS
def getHeader(ass_file):
HEADER = ""
with open(ass_file, 'r') as f:
events_section = False
for line in f.readlines():
if not events_section:
HEADER += line
if re.match("^\[Events\].*", line):
events_section = True
else:
event_regex = "(?:Format:.*)|(?:^Comment:.*(\d+:\d{2}:\d{2}.\d{2}),(\d+:\d{2}:\d{2}.\d{2}),.*,((?!karaoke).)*,((?!karaoke).)*\n$)"
if re.match(event_regex, line):
HEADER += line
return HEADER
......@@ -55,8 +69,9 @@ class AssWriter:
def closeAss(self):
self.file.close()
def writeHeader(self):
header = '''[Script Info]
def writeHeader(self, header=None):
if not header:
header = '''[Script Info]
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
......@@ -79,7 +94,7 @@ Comment: 0,0:00:03.68,0:00:05.68,Default,,0,0,0,code syl all,bord = line.stylere
Comment: 0,0:00:05.68,0:00:05.68,Default,,0,0,0,,
Comment: 0,0:00:05.68,0:00:05.68,Default,,0,0,0,,
Comment: 10,0:00:05.68,0:00:10.43,Default,,0,0,0,template char noblank all,!retime("start2syl",line_in_retime,syl_shift)!{\\fad(!fade_in_dur!,0)\\bord!bord!\shad!shadow!\\blur!blur!\\3c!line.styleref.color3!\c!line.styleref.color3!\pos($x,$y)}
Comment: 20,0:00:05.68,0:00:10.43,Default,,0,0,0,template char noblank all,!retime("start2syl",line_in_retime,syl_shift)!{\fad(200,0)\\bord0\shad0\c!line.styleref.color2!\pos($x,$y)}
Comment: 20,0:00:05.68,0:00:10.43,Default,,0,0,0,template char noblank all,!retime("start2syl",line_in_retime,syl_shift)!{\\fad(200,0)\\bord0\shad0\c!line.styleref.color2!\pos($x,$y)}
Comment: 10,0:00:05.68,0:00:10.43,Default,,0,0,0,template char noblank all,!retime("syl",syl_shift,syl_shift-$dur/syl_in_speed)!{\\3c!line.styleref.color3!\c!line.styleref.color3!\\bord!bord!\shad!shadow!\\blur!blur!\move($x,$y,$x,!$y-($height/8)!,0,!($dur > syl_in_speed * 400 and 400 or $dur/syl_in_speed)!)}
Comment: 40,0:00:05.68,0:00:10.43,Default,,0,0,0,template char noblank all,!retime("syl",syl_shift,syl_shift-$dur/syl_in_speed)!{\\bord0\shad0\c!line.styleref.color2!\\t(0,!($dur > syl_in_speed * 400 and 400 or $dur/syl_in_speed)!,\c!line.styleref.color1!)\move($x,$y,$x,!$y-($height/8)!,0,!($dur > syl_in_speed * 400 and 400 or $dur/syl_in_speed)!)}
Comment: 10,0:00:05.68,0:00:10.43,Default,,0,0,0,template char noblank all,!retime("postsyl",syl_shift-$dur/syl_in_speed,($lstart + $send + ($dur/12)) < ($lend + 300) and $dur/12 or $lend - $lstart - $send + 300)!{\\3c!line.styleref.color3!\c!line.styleref.color3!\\bord!bord!\shad!shadow!\\blur!blur!\move($x,!$y-($height/8)!,$x,!$y!,0,!$dur/syl_out_speed!)!($lstart + $end + $dur/12) < ($lend + 300) and "" or "\\fad(0,150)"!}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter