Module subtp::srt

source ·
Expand description

A parser for the SubRip Subtitle (.srt) format provided by subtp::srt::SubRip.

§Example

use subtp::srt::SubRip;
use subtp::srt::SrtSubtitle;
use subtp::srt::SrtTimestamp;

let text = r#"1
00:00:01,000 --> 00:00:02,000
Hello, world!

2
00:00:03,000 --> 00:00:04,000
This is a sample.
Thank you for your reading.
"#;

let srt = SubRip::parse(text).unwrap();
assert_eq!(srt, SubRip {
    subtitles: vec![
        SrtSubtitle {
            sequence: 1,
            start: SrtTimestamp {
                hours: 0,
                minutes: 0,
                seconds: 1,
                milliseconds: 0,
            },
            end: SrtTimestamp {
                hours: 0,
                minutes: 0,
                seconds: 2,
                milliseconds: 0,
            },
            text: vec!["Hello, world!".to_string()],
            line_position: None,
        },
        SrtSubtitle {
            sequence: 2,
            start: SrtTimestamp {
                hours: 0,
                minutes: 0,
                seconds: 3,
                milliseconds: 0,
            },
            end: SrtTimestamp {
                hours: 0,
                minutes: 0,
                seconds: 4,
                milliseconds: 0,
            },
            text: vec![
                "This is a sample.".to_string(),
                "Thank you for your reading.".to_string()
            ],
            line_position: None,
        },
    ],
});

let rendered = srt.render();
assert_eq!(rendered, text);

Structs§