refactor: pass individual parameters to command handlers instead of command tuple
This commit is contained in:
parent
8f3c0931bf
commit
98cedc4be3
1 changed files with 9 additions and 9 deletions
18
merge_srt.py
18
merge_srt.py
|
@ -87,15 +87,17 @@ class SRTMerger:
|
||||||
def process_commands(self):
|
def process_commands(self):
|
||||||
for cmd in self.commands:
|
for cmd in self.commands:
|
||||||
if cmd[0] == 'COPY':
|
if cmd[0] == 'COPY':
|
||||||
self.handle_copy(cmd)
|
_, source, start, end = cmd
|
||||||
|
self.handle_copy(source, start, end)
|
||||||
elif cmd[0] == 'MAP':
|
elif cmd[0] == 'MAP':
|
||||||
self.handle_map(cmd)
|
_, text_source, text_start, time_source, time_start, count = cmd
|
||||||
|
self.handle_map(text_source, text_start, time_source, time_start, count)
|
||||||
elif cmd[0] == 'SYNC':
|
elif cmd[0] == 'SYNC':
|
||||||
self.handle_sync(cmd)
|
_, text_source, text_index, time_index = cmd
|
||||||
|
self.handle_sync(text_source, text_index, time_index)
|
||||||
self.write_output()
|
self.write_output()
|
||||||
|
|
||||||
def handle_copy(self, cmd):
|
def handle_copy(self, source, start, end):
|
||||||
source, start, end = cmd[1:]
|
|
||||||
source_list = self.srt1 if source == 1 else self.srt2
|
source_list = self.srt1 if source == 1 else self.srt2
|
||||||
start_idx, end_idx = start - 1, end - 1
|
start_idx, end_idx = start - 1, end - 1
|
||||||
if start_idx < 0 or end_idx >= len(source_list) or start_idx > end_idx:
|
if start_idx < 0 or end_idx >= len(source_list) or start_idx > end_idx:
|
||||||
|
@ -103,8 +105,7 @@ 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, cmd):
|
def handle_map(self, text_source, text_start, time_source, time_start, count):
|
||||||
text_source, text_start, time_source, time_start, count = cmd[1:]
|
|
||||||
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
|
||||||
|
@ -121,8 +122,7 @@ class SRTMerger:
|
||||||
'text': text_entry['text'],
|
'text': text_entry['text'],
|
||||||
})
|
})
|
||||||
|
|
||||||
def handle_sync(self, cmd):
|
def handle_sync(self, text_source, text_index, time_index):
|
||||||
text_source, text_index, time_index = cmd[1:]
|
|
||||||
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.srt2 if text_source == 1 else self.srt1
|
time_list = self.srt2 if text_source == 1 else self.srt1
|
||||||
text_start_idx = text_index - 1
|
text_start_idx = text_index - 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue