feat: allow MAP command to use textstart-textend range
This commit is contained in:
parent
91caba2091
commit
ea413d2e3e
1 changed files with 23 additions and 5 deletions
28
merge_srt.py
28
merge_srt.py
|
@ -99,16 +99,34 @@ class SRTMerger:
|
||||||
return ('COPY', source, start, end)
|
return ('COPY', source, start, end)
|
||||||
|
|
||||||
def parse_map(self, parts):
|
def parse_map(self, parts):
|
||||||
if len(parts) != 5:
|
if len(parts) not in (4, 5):
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
text_source = int(parts[1])
|
text_source = int(parts[1])
|
||||||
if text_source not in (1, 2):
|
if text_source not in (1, 2):
|
||||||
return None
|
return None
|
||||||
text_start = int(parts[2])
|
if len(parts) == 4:
|
||||||
time_start = int(parts[3])
|
# New syntax: textstart-textend
|
||||||
count = int(parts[4])
|
range_str = parts[2]
|
||||||
if text_start < 1 or time_start < 1 or count < 1:
|
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
|
return None
|
||||||
except (ValueError, AttributeError, TypeError):
|
except (ValueError, AttributeError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue