fix: remove time_source from MAP command, deduce from text_source
This commit is contained in:
parent
56187476c3
commit
9a57fc40b7
1 changed files with 8 additions and 8 deletions
16
merge_srt.py
16
merge_srt.py
|
@ -53,21 +53,20 @@ class SRTMerger:
|
||||||
continue
|
continue
|
||||||
commands.append(('COPY', source, start, end))
|
commands.append(('COPY', source, start, end))
|
||||||
elif command == 'MAP':
|
elif command == 'MAP':
|
||||||
if len(parts) != 7:
|
if len(parts) != 6:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
text_source = int(parts[1])
|
text_source = int(parts[1])
|
||||||
text_start = int(parts[2])
|
text_start = int(parts[2])
|
||||||
time_source = int(parts[3])
|
time_start = int(parts[3])
|
||||||
time_start = int(parts[4])
|
count = int(parts[4])
|
||||||
count = int(parts[5])
|
if text_source not in (1, 2):
|
||||||
if text_source not in (1, 2) or time_source not in (1, 2):
|
|
||||||
continue
|
continue
|
||||||
if text_start < 1 or time_start < 1 or count < 1:
|
if text_start < 1 or time_start < 1 or count < 1:
|
||||||
continue
|
continue
|
||||||
except (ValueError, AttributeError):
|
except (ValueError, AttributeError):
|
||||||
continue
|
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':
|
elif command == 'SYNC':
|
||||||
if len(parts) != 5:
|
if len(parts) != 5:
|
||||||
continue
|
continue
|
||||||
|
@ -125,14 +124,15 @@ class SRTMerger:
|
||||||
return
|
return
|
||||||
self.output.extend(source_list[start_idx:end_idx + 1])
|
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
|
text_list = self.srt1 if text_source == 1 else self.srt2
|
||||||
time_list = self.srt1 if time_source == 1 else self.srt2
|
time_list = self.srt1 if time_source == 1 else self.srt2
|
||||||
text_start_idx = text_start - 1
|
text_start_idx = text_start - 1
|
||||||
time_start_idx = time_start - 1
|
time_start_idx = time_start - 1
|
||||||
if (text_start_idx < 0 or text_start_idx + count > len(text_list) or
|
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)):
|
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
|
return
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
text_entry = text_list[text_start_idx + i]
|
text_entry = text_list[text_start_idx + i]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue