Skip to content

Commit

Permalink
Fix for noophq#28
Browse files Browse the repository at this point in the history
  • Loading branch information
berndmoos committed May 11, 2024
1 parent dffa688 commit 0bce317
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/main/java/fr/noop/subtitle/vtt/VttParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private enum CursorStatus {
EMPTY_LINE,
CUE_ID,
CUE_TIMECODE,
NOTE,
CUE_TEXT;
}

Expand All @@ -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

Expand All @@ -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;
}
Expand All @@ -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
}

Expand Down

0 comments on commit 0bce317

Please sign in to comment.