Skip to content

Commit 980e8f3

Browse files
committed
[YouTube] *.srt numbering start at 1 instead of 0. (issue: #12670)
- The SubRip (.srt) specification requires subtitle numbering to begin from 1. - Please refer to https://en.wikipedia.org/wiki/SubRip - Previously numbering started from 0, which is accepted by most players (tested on mpv, VLC, MPlayer, Totem) but not strictly compliant.
1 parent eed09f8 commit 980e8f3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/src/main/java/org/schabi/newpipe/streams/SrtFromTtmlWriter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public class SrtFromTtmlWriter {
2424
private final boolean ignoreEmptyFrames;
2525
private final Charset charset = StandardCharsets.UTF_8;
2626

27-
private int frameIndex = 0;
27+
// According to the SubRip (.srt) specification, subtitle
28+
// numbering must start from 1.
29+
// Some players accept 0 or even negative indices,
30+
// but to ensure compliance we start at 1.
31+
private int frameIndex = 1;
2832

2933
public SrtFromTtmlWriter(final SharpStream out, final boolean ignoreEmptyFrames) {
3034
this.out = out;
@@ -39,7 +43,8 @@ private static String getTimestamp(final Element frame, final String attr) {
3943

4044
private void writeFrame(final String begin, final String end, final StringBuilder text)
4145
throws IOException {
42-
writeString(String.valueOf(frameIndex++));
46+
writeString(String.valueOf(frameIndex));
47+
frameIndex += 1;
4348
writeString(NEW_LINE);
4449
writeString(begin);
4550
writeString(" --> ");

0 commit comments

Comments
 (0)