Crates.io | aspasia |
lib.rs | aspasia |
version | 0.2.1 |
source | src |
created_at | 2023-12-09 06:04:23.15649 |
updated_at | 2024-06-30 16:26:17.712805 |
description | Library for parsing and working with subtitles |
homepage | |
repository | https://github.com/ylysyym/aspasia |
max_upload_size | |
id | 1063452 |
size | 191,450 |
aspasia is a subtitle parsing library written in Rust that offers various functionality for working with subtitles.
Parsing of formats is done somewhat loosely, meaning that it will make a best effort to parse subtitle files as the given format, even if they don't fit the specification perfectly. Parsing incorrectly formatted subtitle files will result in an empty object instead of returning any errors.
https://docs.rs/aspasia/latest/aspasia/
You can add aspasia to your project using Cargo: cargo add aspasia
...or you can edit your Cargo.toml
to add:
[dependencies]
aspasia = "0.2"
Basic usage
use aspasia::{SubRipSubtitle, Subtitle, TimedEvent, TimedSubtitleFile, WebVttSubtitle};
// 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")?;
Format conversion
use aspasia::{AssSubtitle, SubRipSubtitle, Subtitle, TimedSubtitleFile, WebVttSubtitle};
let sub = TimedSubtitleFile::new("/path/to/file.srt")?;
// Get the file as its specific format
let srt = SubRipSubtitle::from(sub);
// You can use into() to convert the file
let vtt: WebVttSubtitle = srt.into();
// or from()
let ass = AssSubtitle::from(vtt);
ass.export("/path/to/converted.ass")?;
See examples folder for more
aspasia is currently under development, and its API is not necessarily stable. Once both API and functionality are relatively stable, I would like to release a 1.0 version. To that end, any feedback, bug reports, or other forms of contribution are very welcome.
aspasia is licensed under the BSD 0-Clause license.