diff --git a/merge_srt.py b/merge_srt.py index 3db1214..30831b7 100644 --- a/merge_srt.py +++ b/merge_srt.py @@ -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]