Browse Source

[YouTube] parse timestamps with >3 digits correctly (#775)

* [YouTube] parse timestamps with >3 digits correctly

Fixes https://github.com/TeamNewPipe/NewPipe/issues/7530; check the
issue for details.

* Remove outdated comment
pull/769/merge
Mohammed Anas 2 weeks ago
committed by GitHub
parent
commit
65df39b3e3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java
  2. 6
      extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java
  3. 4
      extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java

2
extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

@ -302,7 +302,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
@Override
public long getTimeStamp() throws ParsingException {
final long timestamp =
getTimestampSeconds("((#|&|\\?)t=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)");
getTimestampSeconds("((#|&|\\?)t=\\d*h?\\d*m?\\d+s?)");
if (timestamp == -2) {
// Regex for timestamp was not found

6
extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java

@ -441,9 +441,9 @@ public abstract class StreamExtractor extends Extractor {
String minutesString = "";
String hoursString = "";
try {
secondsString = Parser.matchGroup1("(\\d{1,3})s", timeStamp);
minutesString = Parser.matchGroup1("(\\d{1,3})m", timeStamp);
hoursString = Parser.matchGroup1("(\\d{1,3})h", timeStamp);
secondsString = Parser.matchGroup1("(\\d+)s", timeStamp);
minutesString = Parser.matchGroup1("(\\d+)m", timeStamp);
hoursString = Parser.matchGroup1("(\\d+)h", timeStamp);
} catch (Exception e) {
//it could be that time is given in another method
if (secondsString.isEmpty() //if nothing was got,

4
extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java

@ -112,8 +112,8 @@ public class YoutubeStreamExtractorDefaultTest {
public static class DescriptionTestPewdiepie extends DefaultStreamExtractorTest {
private static final String ID = "7PIMiDcwNvc";
private static final int TIMESTAMP = 17;
private static final String URL = BASE_URL + ID + "&t=" + TIMESTAMP;
private static final int TIMESTAMP = 7483;
private static final String URL = BASE_URL + ID + "&t=" + TIMESTAMP + "s";
private static StreamExtractor extractor;
@BeforeClass

Loading…
Cancel
Save