subtp
A parser in Rust for subtitle text formats such as the SubRip Subtitle (.srt) format and the WebVTT (.vtt) format.
Installation
Run the following Cargo command in your project directory:
cargo add subtp
or add the following line to your Cargo.toml:
[]
= "0.1.0"
Features
- SubRip Subtitle (.srt) parser and renderer.
- WebVTT (.vtt) parser and renderer.
Usage
SubRip Subtitle (.srt)
Parse a SubRip Subtitle (.srt) text into a subtp::srt::SubRip struct.
use SubRip;
let text = r#"
1
00:00:00,000 --> 00:00:02,000
Hello, world!
2
00:00:02,000 --> 00:00:04,000
This is a subtitle.
"#;
let subrip = parse?;
Render a subtp::srt::SubRip struct into a SubRip Subtitle (.srt) text.
subtp::srt::SubRip is constructed with a vector of subtp::srt::SrtSubtitle.
use ;
let subrip = SubRip ;
let text = subrip.render;
WebVTT (.vtt)
Parse a WebVTT (.vtt) text into a subtp::vtt::WebVTT struct.
use WebVtt;
let text = r#"WEBVTT
1
00:00:00.000 --> 00:00:02.000
Hello, world!
2
00:00:02.000 --> 00:00:04.000
This is a subtitle.
"#;
let webvtt = parse?;
Render a subtp::vtt::WebVTT struct into a WebVTT (.vtt) text.
subtp::vtt::WebVTT is constructed with a header subtp::vtt::VttHeader and a vector of subtp::vtt::VttBlcok.
subtp::vtt::VttBlcok can be following types:
subtp::vtt::VttCue- Cue block with an identifier (Optional), timings, settings (Optional) and a subtitle text.
subtp::vtt::VttComment- Comment block with a noting text.
subtp::vtt::VttStyle- Style block with a CSS style text.
subtp::vtt::VttRegion- Region block with a region definition.
use ;
let webvtt = WebVtt ;
let text = webvtt.render;
Other examples
See the ./examples directory.
Changelog
See CHANGELOG.
License
Licensed under either of the Apache License, Version 2.0 or the MIT license at your option.