feat: allow MAP command to use textstart-textend range

This commit is contained in:
Emmanuel BENOîT 2025-04-07 10:31:23 +02:00
parent 91caba2091
commit ea413d2e3e
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg

View file

@ -99,16 +99,34 @@ class SRTMerger:
return ('COPY', source, start, end)
def parse_map(self, parts):
if len(parts) != 5:
if len(parts) not in (4, 5):
return None
try:
text_source = int(parts[1])
if text_source not in (1, 2):
return None
text_start = int(parts[2])
time_start = int(parts[3])
count = int(parts[4])
if text_start < 1 or time_start < 1 or count < 1:
if len(parts) == 4:
# New syntax: textstart-textend
range_str = parts[2]
start_end = range_str.split('-')
if len(start_end) != 2:
return None
text_start = int(start_end[0])
text_end = int(start_end[1])
if text_start < 1 or text_end < text_start:
return None
count = text_end - text_start + 1
time_start = int(parts[3])
else:
# Original syntax: textstart, timestart, count
text_start = int(parts[2])
time_start = int(parts[3])
count = int(parts[4])
if text_start < 1 or time_start < 1 or count < 1:
return None
text_end = text_start + count - 1
# Common checks
if time_start < 1 or count < 1:
return None
except (ValueError, AttributeError, TypeError):
return None