pub struct SubtitleTrack {
pub events: Vec<SubtitleEvent>,
pub language: Option<String>,
}Expand description
A parsed subtitle track containing ordered events.
Fields§
§events: Vec<SubtitleEvent>Ordered list of subtitle events.
language: Option<String>BCP-47 language tag when available (e.g. "en", "ja").
Implementations§
Source§impl SubtitleTrack
impl SubtitleTrack
Sourcepub fn from_srt(input: &str) -> Result<Self, SubtitleError>
pub fn from_srt(input: &str) -> Result<Self, SubtitleError>
Parse a SubRip (.srt) subtitle string.
Supports multi-line cues and HTML-style tags (<i>, <b>, <u>).
Malformed blocks are skipped with log::warn!.
§Errors
Returns SubtitleError::NoEvents when no valid events are found.
Sourcepub fn from_ass(input: &str) -> Result<Self, SubtitleError>
pub fn from_ass(input: &str) -> Result<Self, SubtitleError>
Parse an ASS/SSA subtitle string.
Reads the [Events] section only. Override tags ({...}) are
preserved in SubtitleEvent::raw and stripped for
SubtitleEvent::text. Malformed Dialogue: lines are skipped.
§Errors
Returns SubtitleError::NoEvents when no valid events are found.
Sourcepub fn from_vtt(input: &str) -> Result<Self, SubtitleError>
pub fn from_vtt(input: &str) -> Result<Self, SubtitleError>
Parse a WebVTT (.vtt) subtitle string.
Cue identifiers are optional. Voice span tags (<v Speaker>) and
other HTML tags are stripped for SubtitleEvent::text. Malformed
cues are skipped with log::warn!.
§Errors
Returns SubtitleError::ParseError when the WEBVTT header is
missing, or SubtitleError::NoEvents when no valid cues are found.
Sourcepub fn to_srt(&self) -> String
pub fn to_srt(&self) -> String
Serialize this track to a SubRip (.srt) string.
Events are numbered sequentially starting at 1. The raw field is
written as the cue body so that style tags round-trip intact.
Events with empty text produce a blank-line body so that the sequential
index is preserved.
Timestamp format: HH:MM:SS,mmm --> HH:MM:SS,mmm.
Sourcepub fn to_ass(&self) -> String
pub fn to_ass(&self) -> String
Serialize this track to an ASS/SSA string.
Writes a minimal but valid file containing [Script Info],
[V4+ Styles] (one default style), and [Events]. The raw field
is written as the Text column so that override tags round-trip intact.
Style and Name metadata fields are restored from
SubtitleEvent::metadata when present.
Timestamp format: H:MM:SS.cc (centiseconds).
Sourcepub fn to_vtt(&self) -> String
pub fn to_vtt(&self) -> String
Serialize this track to a WebVTT (.vtt) string.
Writes the mandatory WEBVTT header followed by one cue per event.
The raw field is written as the cue body so that voice span tags
round-trip intact.
Timestamp format: HH:MM:SS.mmm --> HH:MM:SS.mmm.
Sourcepub fn write_to_file(&self, path: impl AsRef<Path>) -> Result<(), SubtitleError>
pub fn write_to_file(&self, path: impl AsRef<Path>) -> Result<(), SubtitleError>
Write this track to path, choosing the serializer by file extension.
Supported extensions: .srt, .ass, .ssa, .vtt.
§Errors
Returns SubtitleError::UnsupportedFormat for unrecognized extensions,
or SubtitleError::Io when the file cannot be written.
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, SubtitleError>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, SubtitleError>
Load and parse a subtitle file, auto-detecting the format by extension.
Supported extensions: .srt, .ass, .ssa, .vtt.
§Errors
Returns SubtitleError::UnsupportedFormat for unrecognized extensions,
SubtitleError::Io on read failure, or a format-specific error when
parsing fails.
Trait Implementations§
Source§impl Clone for SubtitleTrack
impl Clone for SubtitleTrack
Source§fn clone(&self) -> SubtitleTrack
fn clone(&self) -> SubtitleTrack
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more