Add function to fix Start/End Chars on Subtitles

This commit is contained in:
rlaphoenix 2023-05-30 20:22:40 +01:00
parent 6cfbaa7db1
commit d369e6134c
1 changed files with 24 additions and 0 deletions

View File

@ -385,6 +385,30 @@ class Subtitle(Track):
) )
sub.save() sub.save()
def reverse_rtl(self) -> None:
"""
Reverse RTL (Right to Left) Start/End on Captions.
This can be used to fix the positioning of sentence-ending characters.
"""
if not self.path or not self.path.exists():
raise ValueError("You must download the subtitle track first.")
executable = get_binary_path("SubtitleEdit")
if not executable:
raise EnvironmentError("SubtitleEdit executable not found...")
subprocess.run(
[
executable,
"/Convert", self.path, "srt",
"/ReverseRtlStartEnd",
"/encoding:utf8",
"/overwrite"
],
check=True,
stdout=subprocess.DEVNULL
)
def __str__(self) -> str: def __str__(self) -> str:
return " | ".join(filter(bool, [ return " | ".join(filter(bool, [
"SUB", "SUB",