Trait aspasia::TimedEvent
source · pub trait TimedEvent: TimedEventInterface {
// Provided methods
fn shift(&mut self, delta: TimeDelta) { ... }
fn duration(&self) -> TimeDelta { ... }
}
Expand description
Helper methods for time-based subtitle events.
Provided Methods§
sourcefn shift(&mut self, delta: TimeDelta)
fn shift(&mut self, delta: TimeDelta)
Shift subtitle event by given amount of time in milliseconds.
Positive numbers will result in the subtitle event appearing later, while negative numbers will make the event appear earlier.
Examples found in repository?
examples/modification.rs (line 13)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() -> Result<(), Error> {
let sub = TimedSubtitleFile::new("/path/to/subtitle.ass")?;
let mut ass = AssSubtitle::from(sub);
println!("{}", ass.script_info());
for event in ass.events_mut() {
event.style = Some("Karaoke".to_string());
if event.duration() > TimeDelta::from(500) {
event.shift(2000.into());
}
}
ass.export("/path/to/output.ass")
}
More examples
examples/basic.rs (line 22)
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(())
}
sourcefn duration(&self) -> TimeDelta
fn duration(&self) -> TimeDelta
Get duration of event in milliseconds, as a TimeDelta
Examples found in repository?
examples/modification.rs (line 12)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() -> Result<(), Error> {
let sub = TimedSubtitleFile::new("/path/to/subtitle.ass")?;
let mut ass = AssSubtitle::from(sub);
println!("{}", ass.script_info());
for event in ass.events_mut() {
event.style = Some("Karaoke".to_string());
if event.duration() > TimeDelta::from(500) {
event.shift(2000.into());
}
}
ass.export("/path/to/output.ass")
}