Struct aspasia::SubRipSubtitle
source · pub struct SubRipSubtitle { /* private fields */ }
Expand description
SubRip (.srt) subtitle data, containing only a list of events.
Implementations§
source§impl SubRipSubtitle
impl SubRipSubtitle
sourcepub fn from_events(events: Vec<SubRipEvent>) -> Self
pub fn from_events(events: Vec<SubRipEvent>) -> Self
Creates a new SubRip (.srt) subtitle from an already existing list of SubRipEvent
s
sourcepub fn renumber(&mut self)
pub fn renumber(&mut self)
Renumbers all events according to the order they are stored in.
This modifies the line number of all events, starting from 1 for the first event and incrementing by 1 for each subsequent event.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() -> Result<(), Error> {
// We can directly specify the format to open a subtitle file
let vtt = WebVttSubtitle::from_path("/path/to/some.vtt")?;
// and then directly work with its data
println!("{}", vtt.header().cloned().unwrap_or_default());
// or we could use the more general interface to open (timed) subtitle files
let sub = TimedSubtitleFile::new("/path/to/file.srt")?;
// Move the underlying data out in order to access format-specific properties
// Note that if the format doesn't match, this will perform a conversion instead of just moving the data
let mut srt = SubRipSubtitle::from(sub);
// Now we can access format-specific methods like SubRipSubtitle::renumber()
srt.renumber();
// Access and modify events
for event in srt.events_mut() {
event.shift(600.into());
}
// Write the modified subtitle to file
srt.export("/path/to/output.srt")?;
Ok(())
}
Trait Implementations§
source§impl Clone for SubRipSubtitle
impl Clone for SubRipSubtitle
source§fn clone(&self) -> SubRipSubtitle
fn clone(&self) -> SubRipSubtitle
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SubRipSubtitle
impl Debug for SubRipSubtitle
source§impl Display for SubRipSubtitle
impl Display for SubRipSubtitle
source§impl From<&AssSubtitle> for SubRipSubtitle
impl From<&AssSubtitle> for SubRipSubtitle
source§fn from(value: &AssSubtitle) -> Self
fn from(value: &AssSubtitle) -> Self
Convert Advanced SubStation Alpha (.ass) subtitles to .srt format
Replaces SubStation newline indicators (\N) with actual newlines. Additionally, converts .ass style formatting tags to .srt formatting tags. Currently, bolded, italicised, underlined, or coloured text will be converted to their .srt counterparts. All other tags will be discarded.
source§impl From<&SsaSubtitle> for SubRipSubtitle
impl From<&SsaSubtitle> for SubRipSubtitle
source§fn from(value: &SsaSubtitle) -> Self
fn from(value: &SsaSubtitle) -> Self
Convert SubStation Alpha (.ssa) subtitles to .srt format
Replaces SubStation newline indicators (\N) with actual newlines. Additionally, converts .ssa style formatting tags to .srt formatting tags. Currently, bolded, italicised, or coloured text will be converted to their .srt counterparts. All other tags will be discarded.
source§impl From<&SubRipSubtitle> for AssSubtitle
impl From<&SubRipSubtitle> for AssSubtitle
source§fn from(value: &SubRipSubtitle) -> Self
fn from(value: &SubRipSubtitle) -> Self
Convert SubRip (.srt) subtitle to .ass format.
This will replace newlines and convert HTML formatting tags (<b>
, <i>
, etc.) into .ass style formatting tags
source§impl From<&SubRipSubtitle> for SsaSubtitle
impl From<&SubRipSubtitle> for SsaSubtitle
source§fn from(value: &SubRipSubtitle) -> Self
fn from(value: &SubRipSubtitle) -> Self
Convert SubRip (.srt) subtitle to .ssa format.
This will replace newlines and convert HTML formatting tags (<b>
, <i>
, etc.) into .ssa style formatting tags
source§impl From<&SubRipSubtitle> for TimedMicroDvdSubtitle
impl From<&SubRipSubtitle> for TimedMicroDvdSubtitle
source§fn from(value: &SubRipSubtitle) -> Self
fn from(value: &SubRipSubtitle) -> Self
source§impl From<&SubRipSubtitle> for WebVttSubtitle
impl From<&SubRipSubtitle> for WebVttSubtitle
source§fn from(value: &SubRipSubtitle) -> Self
fn from(value: &SubRipSubtitle) -> Self
Convert a SubRip (.srt) subtitle to WebVTT format.
This sets the line number as the cue identifier.
The supported tags are <b>
, <i>
, and <u>
. Any other tags will be stripped from the text.
Bracket tags (of the form {b}
) will be converted to HTML tags (<b>
).
source§impl From<&TimedMicroDvdSubtitle> for SubRipSubtitle
impl From<&TimedMicroDvdSubtitle> for SubRipSubtitle
source§fn from(value: &TimedMicroDvdSubtitle) -> Self
fn from(value: &TimedMicroDvdSubtitle) -> Self
source§impl From<&WebVttSubtitle> for SubRipSubtitle
impl From<&WebVttSubtitle> for SubRipSubtitle
source§fn from(value: &WebVttSubtitle) -> Self
fn from(value: &WebVttSubtitle) -> Self
Convert WebVTT (.vtt) subtitle to .srt format
Cue identifiers that are numbers will be treated as line numbers for the corresponding event in the .srt output.