pub enum SubtitleFile {
SubRipFile(SrtFile),
SubStationAlpha(SsaFile),
VobSubIdxFile(IdxFile),
VobSubSubFile(VobFile),
MicroDVDFile(MdvdFile),
}
Expand description
Unified wrapper around the all individual subtitle file types.
Variants§
SubRipFile(SrtFile)
.srt file
SubStationAlpha(SsaFile)
.ssa/.ass file
VobSubIdxFile(IdxFile)
.idx file
VobSubSubFile(VobFile)
.sub file (VobSub
/binary)
MicroDVDFile(MdvdFile)
.sub file (MicroDVD
/text)
Implementations§
Source§impl SubtitleFile
impl SubtitleFile
Sourcepub fn get_subtitle_entries(&self) -> Result<Vec<SubtitleEntry>>
pub fn get_subtitle_entries(&self) -> Result<Vec<SubtitleEntry>>
The subtitle entries can be changed by calling update_subtitle_entries()
.
Examples found in repository?
16fn main() {
17 // your setup goes here
18 let path = PathBuf::from("path/your_example_file.ssa");
19 let file_content: String = read_file(&path); // your own load routine
20
21 // parse the file
22 let format = get_subtitle_format(path.extension(), file_content.as_bytes()).expect("unknown format");
23 let mut subtitle_file = parse_str(format, &file_content, 25.0).expect("parser error");
24 let mut subtitle_entries: Vec<SubtitleEntry> = subtitle_file.get_subtitle_entries().expect("unexpected error");
25
26 // shift all subtitle entries by 1 minute and append "subparse" to each subtitle line
27 for subtitle_entry in &mut subtitle_entries {
28 subtitle_entry.timespan += TimeDelta::from_mins(1);
29
30 // image based subtitles like .idx (VobSub) don't have text, so
31 // a text is optional
32 if let Some(ref mut line_ref) = subtitle_entry.line {
33 line_ref.push_str("subparse");
34 }
35 }
36
37 // update the entries in the subtitle file
38 subtitle_file.update_subtitle_entries(&subtitle_entries).expect("unexpected error");
39
40 // print the corrected file to stdout
41 let data: Vec<u8> = subtitle_file.to_data().expect("unexpected errror");
42 let data_string = String::from_utf8(data).expect("UTF-8 conversion error");
43 println!("{}", data_string);
44}
Sourcepub fn update_subtitle_entries(&mut self, i: &[SubtitleEntry]) -> Result<()>
pub fn update_subtitle_entries(&mut self, i: &[SubtitleEntry]) -> Result<()>
Set the entries from the subtitle entries from the get_subtitle_entries()
.
The length of the given input slice should always match the length of the vector length from
get_subtitle_entries()
. This function can not delete/create new entries, but preserves
everything else in the file (formatting, authors, …).
If the input entry has entry.line == None
, the line will not be overwritten.
Be aware that .idx files cannot save time_spans_ (a subtitle will be shown between two consecutive timepoints/there are no separate starts and ends) - so the timepoint will be set to the start of the corresponding input-timespan.
Examples found in repository?
16fn main() {
17 // your setup goes here
18 let path = PathBuf::from("path/your_example_file.ssa");
19 let file_content: String = read_file(&path); // your own load routine
20
21 // parse the file
22 let format = get_subtitle_format(path.extension(), file_content.as_bytes()).expect("unknown format");
23 let mut subtitle_file = parse_str(format, &file_content, 25.0).expect("parser error");
24 let mut subtitle_entries: Vec<SubtitleEntry> = subtitle_file.get_subtitle_entries().expect("unexpected error");
25
26 // shift all subtitle entries by 1 minute and append "subparse" to each subtitle line
27 for subtitle_entry in &mut subtitle_entries {
28 subtitle_entry.timespan += TimeDelta::from_mins(1);
29
30 // image based subtitles like .idx (VobSub) don't have text, so
31 // a text is optional
32 if let Some(ref mut line_ref) = subtitle_entry.line {
33 line_ref.push_str("subparse");
34 }
35 }
36
37 // update the entries in the subtitle file
38 subtitle_file.update_subtitle_entries(&subtitle_entries).expect("unexpected error");
39
40 // print the corrected file to stdout
41 let data: Vec<u8> = subtitle_file.to_data().expect("unexpected errror");
42 let data_string = String::from_utf8(data).expect("UTF-8 conversion error");
43 println!("{}", data_string);
44}
Sourcepub fn to_data(&self) -> Result<Vec<u8>>
pub fn to_data(&self) -> Result<Vec<u8>>
Returns a byte-stream in the respective format (.ssa, .srt, etc.) with the (probably) altered information.
Examples found in repository?
16fn main() {
17 // your setup goes here
18 let path = PathBuf::from("path/your_example_file.ssa");
19 let file_content: String = read_file(&path); // your own load routine
20
21 // parse the file
22 let format = get_subtitle_format(path.extension(), file_content.as_bytes()).expect("unknown format");
23 let mut subtitle_file = parse_str(format, &file_content, 25.0).expect("parser error");
24 let mut subtitle_entries: Vec<SubtitleEntry> = subtitle_file.get_subtitle_entries().expect("unexpected error");
25
26 // shift all subtitle entries by 1 minute and append "subparse" to each subtitle line
27 for subtitle_entry in &mut subtitle_entries {
28 subtitle_entry.timespan += TimeDelta::from_mins(1);
29
30 // image based subtitles like .idx (VobSub) don't have text, so
31 // a text is optional
32 if let Some(ref mut line_ref) = subtitle_entry.line {
33 line_ref.push_str("subparse");
34 }
35 }
36
37 // update the entries in the subtitle file
38 subtitle_file.update_subtitle_entries(&subtitle_entries).expect("unexpected error");
39
40 // print the corrected file to stdout
41 let data: Vec<u8> = subtitle_file.to_data().expect("unexpected errror");
42 let data_string = String::from_utf8(data).expect("UTF-8 conversion error");
43 println!("{}", data_string);
44}
Trait Implementations§
Source§impl Clone for SubtitleFile
impl Clone for SubtitleFile
Source§fn clone(&self) -> SubtitleFile
fn clone(&self) -> SubtitleFile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more