Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Keep WebVTT cues whose identifier starts with NOTE

NetterSilver2736a1831ede
diff --git a/crates/captions/src/vtt.rs b/crates/captions/src/vtt.rs
index a1afb2445..9c2f3ae4e 100644
--- a/crates/captions/src/vtt.rs
+++ b/crates/captions/src/vtt.rs
@@ -79,7 +79,7 @@ pub fn parse(text: &str) -> Result<Document> {
let mut seen_cue = false;
for b in blocks {
let first = b[0].trim();
- if !first.contains("-->") && (first == "NOTE" || first.starts_with("NOTE ") || first.starts_with("NOTE\t")) {
+ if !b.iter().any(|l| l.contains("-->")) && (first == "NOTE" || first.starts_with("NOTE ") || first.starts_with("NOTE\t")) {
doc.blocks.push(b.join("\n"));
continue;
}
@@ -190,6 +190,14 @@ mod tests {
assert_eq!(split_voice(closed), (None, closed.to_string()));
}
+ #[test]
+ fn note_prefixed_cue_id_is_a_cue() {
+ let d = parse("WEBVTT\n\nNOTE 1\n00:00:01.000 --> 00:00:02.000\nhello\n").unwrap();
+ assert_eq!(d.cues.len(), 1);
+ assert_eq!(d.cues[0].id.as_deref(), Some("NOTE 1"));
+ assert!(d.blocks.is_empty());
+ }
+
#[test]
fn without_signature() {
let d = parse("00:00:01.000 --> 00:00:02.000\nx\n").unwrap();