forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB1f91eddTahinli2 months ago3507 commits

lib.rs33 lines, 1.5 KiBHistoryRawDownload
1//! Text subtitles: SubRip and WebVTT into one cue IR ([`ir`]).
2//!
3//! Both formats are read the same way and for the same reason: what a timeline
4//! wants is *when* a line is on screen and *what it says*, and the markup
5//! around that ranges from `<i>` to a dozen dialects of override tag. So a
6//! parse answers with a [`ir::SubtitleTrack`] — cues of time ranges and
7//! [`ir::Segment`] runs — and a caller that draws nothing yet takes
8//! [`ir::plain_text`] and drops the rest.
9//!
10//! Tolerance is the point. Subtitle files are hand-edited, machine-translated,
11//! re-encoded and truncated; a parser that refuses one is a parser that refuses
12//! the file the user actually has. BOMs (UTF-8 and UTF-16), CRLF and lone CR,
13//! invalid UTF-8, missing or wrong indices, dotted fractions, overlapping and
14//! backwards cues all parse. A block this cannot read is skipped and counted
15//! ([`ir::SubtitleTrack::skipped`]); only a document with no timing line in it
16//! at all is an error, because that is a document of another kind.
17//!
18//! ASS/SSA is the same IR from `ec-ass`, and PGS bitmaps from `ec-pgs`.
19
20#![forbid(unsafe_code)]
21
22pub mod ir;
23mod markup;
24pub mod srt;
25pub mod webvtt;
26
27pub use ir::{
28 CuePosition, Segment, SourceFormat, SubtitleCue, SubtitleStyle, SubtitleTrack, TextAlign,
29 plain_text,
30};
31/// The byte-level tolerances every subtitle format needs, shared with `ec-ass`:
32/// BOM and line-ending normalisation, and the clock every one of them writes.
33pub use markup::{decode, parse_clock};