From 980e8f3951c4f166f1596639502a995a574dd01a Mon Sep 17 00:00:00 2001 From: TransZAllen Date: Mon, 29 Sep 2025 14:04:46 +0800 Subject: [PATCH] [YouTube] *.srt numbering start at 1 instead of 0. (issue: https://github.com/TeamNewPipe/NewPipe/issues/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. --- .../org/schabi/newpipe/streams/SrtFromTtmlWriter.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/streams/SrtFromTtmlWriter.java b/app/src/main/java/org/schabi/newpipe/streams/SrtFromTtmlWriter.java index 7aff655a0..1ec78ba21 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/SrtFromTtmlWriter.java +++ b/app/src/main/java/org/schabi/newpipe/streams/SrtFromTtmlWriter.java @@ -24,7 +24,11 @@ public class SrtFromTtmlWriter { private final boolean ignoreEmptyFrames; private final Charset charset = StandardCharsets.UTF_8; - private int frameIndex = 0; + // According to the SubRip (.srt) specification, subtitle + // numbering must start from 1. + // Some players accept 0 or even negative indices, + // but to ensure compliance we start at 1. + private int frameIndex = 1; public SrtFromTtmlWriter(final SharpStream out, final boolean ignoreEmptyFrames) { this.out = out; @@ -39,7 +43,8 @@ public class SrtFromTtmlWriter { private void writeFrame(final String begin, final String end, final StringBuilder text) throws IOException { - writeString(String.valueOf(frameIndex++)); + writeString(String.valueOf(frameIndex)); + frameIndex += 1; writeString(NEW_LINE); writeString(begin); writeString(" --> ");