forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB8dbd683Tahinli3 months ago856 commits

lib.rs37 lines, 1.3 KiBHistoryRawDownload
1//! `oxideav-ass` as edith consumes it, over [`ec_ass`].
2//!
3//! One item: `parse`, answering the same [`SubtitleTrack`] the SubRip and
4//! WebVTT parsers do — the replica hands all three around as one function
5//! pointer type and reads `cues`, `segments` and `plain_text` off the result.
6
7#![forbid(unsafe_code)]
8
9use oxideav_core::Result;
10
11pub use ec_subs::ir::{
12 CuePosition, Segment, SourceFormat, SubtitleCue, SubtitleStyle, SubtitleTrack, TextAlign,
13};
14
15/// Parse an ASS or SSA script.
16pub fn parse(bytes: &[u8]) -> Result<SubtitleTrack> {
17 Ok(ec_ass::parse(bytes)?)
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23
24 #[test]
25 fn a_script_parses_through_the_shim() {
26 type Parse = fn(&[u8]) -> Result<SubtitleTrack>;
27 let parse: Parse = parse;
28 let doc = "[Events]\n\
29 Format: Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text\n\
30 Dialogue: 0,0:00:01.00,0:00:02.00,Default,,0,0,0,,{\\i1}hi{\\i0}\\Nthere\n";
31 let track = parse(doc.as_bytes()).unwrap();
32 assert_eq!(track.cues.len(), 1);
33 assert_eq!(track.cues[0].start_us, 1_000_000);
34 assert_eq!(ec_subs::plain_text(&track.cues[0].segments), "hi\nthere");
35 assert!(!parse(b"not a script").unwrap_err().to_string().is_empty());
36 }
37}