basic/
basic.rs

1use aspasia::{Error, SubRipSubtitle, Subtitle, TimedEvent, TimedSubtitleFile, WebVttSubtitle};
2
3fn main() -> Result<(), Error> {
4    // We can directly specify the format to open a subtitle file
5    let vtt = WebVttSubtitle::from_path("/path/to/some.vtt")?;
6
7    // and then directly work with its data
8    println!("{}", vtt.header().cloned().unwrap_or_default());
9
10    // or we could use the more general interface to open (timed) subtitle files
11    let sub = TimedSubtitleFile::new("/path/to/file.srt")?;
12
13    // Move the underlying data out in order to access format-specific properties
14    // Note that if the format doesn't match, this will perform a conversion instead of just moving the data
15    let mut srt = SubRipSubtitle::from(sub);
16
17    // Now we can access format-specific methods like SubRipSubtitle::renumber()
18    srt.renumber();
19
20    // Access and modify events
21    for event in srt.events_mut() {
22        event.shift(600.into());
23    }
24
25    // Write the modified subtitle to file
26    srt.export("/path/to/output.srt")?;
27
28    Ok(())
29}