fix: remove time_source from MAP command, deduce from text_source

This commit is contained in:
Emmanuel BENOîT 2025-04-06 13:32:12 +02:00
parent 56187476c3
commit 9a57fc40b7
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg

View file

@ -53,21 +53,20 @@ class SRTMerger:
continue
commands.append(('COPY', source, start, end))
elif command == 'MAP':
if len(parts) != 7:
if len(parts) != 6:
continue
try:
text_source = int(parts[1])
text_start = int(parts[2])
time_source = int(parts[3])
time_start = int(parts[4])
count = int(parts[5])
if text_source not in (1, 2) or time_source not in (1, 2):
time_start = int(parts[3])
count = int(parts[4])
if text_source not in (1, 2):
continue
if text_start < 1 or time_start < 1 or count < 1:
continue
except (ValueError, AttributeError):
continue
commands.append(('MAP', text_source, text_start, time_source, time_start, count))
commands.append(('MAP', text_source, text_start, time_start, count))
elif command == 'SYNC':
if len(parts) != 5:
continue
@ -125,14 +124,15 @@ class SRTMerger:
return
self.output.extend(source_list[start_idx:end_idx + 1])
def handle_map(self, text_source, text_start, time_source, time_start, count):
def handle_map(self, text_source, text_start, time_start, count):
time_source = text_source
text_list = self.srt1 if text_source == 1 else self.srt2
time_list = self.srt1 if time_source == 1 else self.srt2
text_start_idx = text_start - 1
time_start_idx = time_start - 1
if (text_start_idx < 0 or text_start_idx + count > len(text_list) or
time_start_idx < 0 or time_start_idx + count > len(time_list)):
print(f"Skipping invalid MAP command: text source {text_source}, start {text_start}, count {count} or time source {time_source}, start {time_start}, count {count}")
print(f"Skipping invalid MAP command: source {text_source}, text start {text_start}, time start {time_start}, count {count}")
return
for i in range(count):
text_entry = text_list[text_start_idx + i]