Crates.io | vtt |
lib.rs | vtt |
version | |
source | src |
created_at | 2024-12-11 03:30:49.829035 |
updated_at | 2024-12-11 03:48:37.403713 |
description | Rust types for serializing and deserializing WebVTT with Serde. |
homepage | https://github.com/Govcraft/vtt |
repository | https://github.com/Govcraft/vtt |
max_upload_size | |
id | 1479501 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
VTT is a Rust library for parsing and writing WebVTT (Web Video Text Tracks) files. It helps you create, edit, and manage WebVTT cues, timestamps, and settings. VTT works smoothly with Serde for easy data handling.
Add VTT to your project's Cargo.toml
:
[dependencies]
vtt = "0.1.0"
serde = { version = "1.0", features = ["derive"] }
Import the prelude to access common types:
use vtt::prelude::*;
use std::time::Duration;
fn main() {
let mut vtt = WebVtt::new();
vtt.add_metadata("Language", "en-US");
let cue = VttCue {
identifier: Some("1".to_string()),
start: VttTimestamp::new(Duration::from_secs(1)),
end: VttTimestamp::new(Duration::from_secs(5)),
settings: None,
payload: "Hello, world!".to_string(),
};
vtt.add_cue(cue);
println!("{}", vtt);
}
Convert a WebVTT string into a WebVtt
instance:
use vtt::prelude::*;
use std::str::FromStr;
fn parse_vtt(content: &str) -> Result<WebVtt, VttParseError> {
WebVtt::from_str(content)
}
fn main() {
let content = "WEBVTT\n\n00:01:02.000 --> 00:03:04.000\nHello, world!";
let vtt = parse_vtt(content).unwrap();
println!("Number of cues: {}", vtt.cues.len());
}
Convert a WebVtt
instance to a WebVTT string:
use vtt::prelude::*;
use std::time::Duration;
fn main() {
let mut vtt = WebVtt::new();
vtt.add_metadata("Language", "en-US");
let cue = VttCue {
identifier: Some("1".to_string()),
start: VttTimestamp::new(Duration::from_secs(1)),
end: VttTimestamp::new(Duration::from_secs(5)),
settings: None,
payload: "Hello, world!".to_string(),
};
vtt.add_cue(cue);
let serialized = vtt.to_string();
println!("{}", serialized);
}
Read the full documentation here.
You can help make VTT better. Follow these steps:
Make sure your code follows the project's style and passes all tests.
This project is licensed under the MIT or Apache-2.0 license.
For questions or support, visit the repository.