Make SubFox production-ready with parallel translation and UI controls
This commit is contained in:
parent
c40b8bed2b
commit
2b1d05f02c
6046 changed files with 798327 additions and 0 deletions
35
app/services/srt_parser.py
Normal file
35
app/services/srt_parser.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import re
|
||||
|
||||
|
||||
def parse_srt(content: str):
|
||||
content = content.replace("\r\n", "\n").replace("\r", "\n").strip()
|
||||
parts = re.split(r"\n\s*\n", content)
|
||||
|
||||
blocks = []
|
||||
|
||||
for part in parts:
|
||||
lines = [line.rstrip() for line in part.split("\n") if line.strip() != ""]
|
||||
|
||||
if len(lines) < 3:
|
||||
continue
|
||||
|
||||
try:
|
||||
index = int(lines[0].strip())
|
||||
times = lines[1].strip()
|
||||
|
||||
if " --> " not in times:
|
||||
continue
|
||||
|
||||
start, end = times.split(" --> ", 1)
|
||||
text = "\n".join(lines[2:]).strip()
|
||||
|
||||
blocks.append({
|
||||
"index": index,
|
||||
"start": start,
|
||||
"end": end,
|
||||
"text": text
|
||||
})
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
return blocks
|
||||
Loading…
Add table
Add a link
Reference in a new issue