pub struct SSAFile {
pub events: Vec<SSAEvent>,
pub styles: Vec<SSAStyle>,
pub info: HashMap<String, String>,
pub format: String,
}
Expand description
Contains the styles,events and info as well as a format mentioning wether it’s .ass
or .ssa
Fields§
§events: Vec<SSAEvent>
§styles: Vec<SSAStyle>
§info: HashMap<String, String>
§format: String
Implementations§
source§impl SSAFile
impl SSAFile
sourcepub fn to_srt(self) -> SRTFile
pub fn to_srt(self) -> SRTFile
Converts the SSAFile to a SRTFile. Due to .srt
being a far less complex
format, most styles are being ignored.
Styling of the text can happen with {i1}aaa{i0}
tags where i
represents
the style and 0
/1
represent the on/off triggers.
.srt
supports HTML-like tags for i
,b
,u
, representing italic, bold, underline.
If found, ssa specific triggers for those supported tags are replaced with their .srt
alternatives.
Examples found in repository?
8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
let mut srt =
rsubs_lib::srt::parse("tests/fixtures/test.srt".to_string()).expect("failed parsing");
for line in srt.lines.iter_mut() {
line.line_end += 20;
line.line_start += 50;
line.line_text.push_str(" Ipsum");
}
println!("{srt}");
let s = Subtitle::from_str("tests/fixtures/test.srt").unwrap();
let a: SSAFile = s.clone().into(); //convert to `.ass` and then back to `.srt`
assert_eq!(format!("{}", a.to_srt()), format!("{s}"));
}
sourcepub fn to_vtt(self) -> VTTFile
pub fn to_vtt(self) -> VTTFile
Converts the SSAFile to a VTTFile.
Styling of the text can happen with {i1}aaa{i0}
tags where i
represents
the style and 0
/1
represent the on/off triggers.
.vtt
supports HTML-like tags for i
,b
,u
, representing italic, bold, underline.
If found, ssa specific triggers for those supported tags are replaced with their .vtt
alternatives.
In addition, if an SSAEvent has a related SSAStyle, the SSAStyle is converted to a VTTStyle that will be wrapped around the lines indicating it.
sourcepub fn to_file(self, path: &str) -> Result<()>
pub fn to_file(self, path: &str) -> Result<()>
Writes the SSAFile to a file specified by a path String.
Examples found in repository?
More examples
7 8 9 10 11 12 13 14 15 16 17 18 19
fn main() {
vtt::VTTFile::from(srt::SRTFile::from_str("./tests/fixtures/test.srt").unwrap()) // Can read either a file or a string
// converts file to WEBVTT
.to_file("./tests/fixtures/ex_test_1.vtt") // Writes the converted subtitle to a file
.unwrap();
ssa::SSAFile::from(vtt::parse("./tests/fixtures/test.vtt".to_string()).unwrap()) // converts file to SSA/ASS
.to_file("./tests/fixtures/ex_test_1.ass")
.unwrap();
srt::SRTFile::from(ssa::parse("./tests/fixtures/test.ass".to_string()).unwrap())
// converts file to SRT
.to_file("./tests/fixtures/ex_test_1.srt")
.unwrap();
}
Trait Implementations§
source§impl Default for SSAFile
impl Default for SSAFile
The Default SSAFile contains a list of Script Info headers populated with safe and usable default values
In general tests, ScaledBorderAndShadows: yes
seems to be somewhat required for subtitles to display properly