9 releases

0.1.8 Feb 25, 2024
0.1.7 Jun 30, 2023
0.1.6 Mar 31, 2023
0.1.3 Oct 20, 2022
0.1.0 Oct 13, 2020

#261 in Filesystem

Download history 2/week @ 2023-12-01 40/week @ 2023-12-08 6/week @ 2023-12-15 84/week @ 2023-12-22 28/week @ 2023-12-29 74/week @ 2024-01-05 60/week @ 2024-01-12 40/week @ 2024-01-19 23/week @ 2024-01-26 26/week @ 2024-02-02 102/week @ 2024-02-09 48/week @ 2024-02-16 240/week @ 2024-02-23 112/week @ 2024-03-01 80/week @ 2024-03-08 41/week @ 2024-03-15

481 downloads per month
Used in 2 crates

MIT/Apache

34KB
502 lines

srtlib

Build Status Version Documentation License

A simple Rust library for handling .srt subtitle files.

srtlib allows you to handle subtitle files as collections of multiple subtitle structs, letting you modify the subtitles without directly messing with the .srt files.

Subtitle collections can be generated by parsing strings or files, but also from the ground up, enabling total control of all the elements of each subtitle.

Usage

Add this to your Cargo.toml:

[dependencies]
srtlib = "0.1"

To read a .srt file:

use srtlib::Subtitles;

// Parse subtitles from file that uses the utf-8 encoding.
let mut subs = Subtitles::parse_from_file("subtitles.srt", None).unwrap();

You can now perform any action you want on the subtitles. For example to move all subtitles 10 seconds forward in time:

// Move every subtitle 10 seconds forward in time.
for s in &mut subs {
    s.add_seconds(10);
}

Finally we can write the subtitles back to a .srt file:

subs.write_to_file("subtitles_fixed.srt", None).unwrap();

For more examples refer to the documentation.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~3MB
~116K SLoC