mirror of
https://github.com/karl0ss/bazarr-ai-sub-generator.git
synced 2025-04-26 06:49:22 +01:00
18 lines
589 B
Python
18 lines
589 B
Python
import os
|
|
from typing import Iterator, TextIO
|
|
from .convert import format_timestamp
|
|
|
|
def write_srt(transcript: Iterator[dict], file: TextIO):
|
|
for i, segment in enumerate(transcript, start=1):
|
|
print(
|
|
f"{i}\n"
|
|
f"{format_timestamp(segment.start, always_include_hours=True)} --> "
|
|
f"{format_timestamp(segment.end, always_include_hours=True)}\n"
|
|
f"{segment.text.strip().replace('-->', '->')}\n",
|
|
file=file,
|
|
flush=True,
|
|
)
|
|
|
|
def filename(path: str):
|
|
return os.path.splitext(os.path.basename(path))[0]
|