Skip to content

Commit

Permalink
Rename fix_webvtt_separator to space_webvtt_headers
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaphoenix committed Dec 2, 2023
1 parent b8cf7a2 commit f214f7f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions devine/core/tracks/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def parse(data: bytes, codec: Subtitle.Codec) -> pycaption.CaptionSet:
caption_set: pycaption.CaptionSet = pycaption.CaptionSet(caption_lists)
return caption_set
if codec == Subtitle.Codec.WebVTT:
text = Subtitle.fix_webvtt_separator(data)
text = Subtitle.space_webvtt_headers(data)
captions: pycaption.CaptionSet = pycaption.WebVTTReader().read(text)
return captions
except pycaption.exceptions.CaptionReadSyntaxError as e:
Expand All @@ -184,10 +184,13 @@ def parse(data: bytes, codec: Subtitle.Codec) -> pycaption.CaptionSet:
raise ValueError(f"Unknown Subtitle Format \"{codec}\"...")

@staticmethod
def fix_webvtt_separator(data: Union[str, bytes]):
def space_webvtt_headers(data: Union[str, bytes]):
"""
Space out the WEBVTT Headers from Captions.
Segmented VTT when merged may have the WEBVTT headers part of the next caption
if they are not separated far enough from the previous caption, hence the \n\n
as they were not separated far enough from the previous caption and ended up
being considered as caption text rather than the header for the next segment.
"""
if isinstance(data, bytes):
data = data.decode("utf8")
Expand Down Expand Up @@ -449,7 +452,7 @@ def fix_webvtt_timestamp(self) -> None:
else:
return

text = Subtitle.fix_webvtt_separator(self.path.read_text("utf8"))
text = Subtitle.space_webvtt_headers(self.path.read_text("utf8"))
fixed = fix_webvtt_timestamp(
text, segment_duration=segment_duration, timescale=timescale
)
Expand Down

0 comments on commit f214f7f

Please sign in to comment.