From 0bce31706d06916a435fbeff230a2db602b081a4 Mon Sep 17 00:00:00 2001 From: berndmoos Date: Sat, 11 May 2024 16:43:21 +0200 Subject: [PATCH] Fix for #28 --- .../java/fr/noop/subtitle/vtt/VttParser.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/fr/noop/subtitle/vtt/VttParser.java b/src/main/java/fr/noop/subtitle/vtt/VttParser.java index 0584542..57b4d54 100644 --- a/src/main/java/fr/noop/subtitle/vtt/VttParser.java +++ b/src/main/java/fr/noop/subtitle/vtt/VttParser.java @@ -33,6 +33,7 @@ private enum CursorStatus { EMPTY_LINE, CUE_ID, CUE_TIMECODE, + NOTE, CUE_TEXT; } @@ -59,13 +60,14 @@ public VttObject parse(InputStream is) throws IOException, SubtitleParsingExcept @Override public VttObject parse(InputStream is, boolean strict) throws IOException, SubtitleParsingException { - // Create srt object + // Create vttObject object VttObject vttObject = new VttObject(); - // Read each lines + // Read each line BufferedReader br = new BufferedReader(new InputStreamReader(is, this.charset)); String textLine = ""; CursorStatus cursorStatus = CursorStatus.NONE; + CursorStatus memorizedCursorStatus = CursorStatus.NONE; VttCue cue = null; String cueText = ""; // Text of the cue @@ -84,9 +86,26 @@ public VttObject parse(InputStream is, boolean strict) throws IOException, Subti cursorStatus = CursorStatus.SIGNATURE; continue; } + + if (textLine.startsWith("NOTE")){ + memorizedCursorStatus = cursorStatus; + cursorStatus = CursorStatus.NOTE; + continue; + } + if (cursorStatus == CursorStatus.NOTE){ + if (textLine.isEmpty()) { + // NOTE section is over + cursorStatus = memorizedCursorStatus; + } + // do nothing in any case + continue; + + } + + + - if (cursorStatus == CursorStatus.SIGNATURE || - cursorStatus == CursorStatus.EMPTY_LINE) { + if (cursorStatus == CursorStatus.SIGNATURE || cursorStatus == CursorStatus.EMPTY_LINE) { if (textLine.isEmpty()) { continue; } @@ -106,16 +125,6 @@ public VttObject parse(InputStream is, boolean strict) throws IOException, Subti continue; } - - if ( - textLine.length() < 16 || - !textLine.substring(13, 16).equals("-->") - ) { - // First textLine is the cue number - cue.setId(textLine); - continue; - } - // There is no cue number }