From aeeae87641f8ca41e62b985ad20f0cf1ed565aa6 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 9 Apr 2020 20:02:41 +0200 Subject: [PATCH] [PeerTube] Parse timestamp from url (previously unimplemented) --- .../extractors/PeertubeStreamExtractor.java | 13 ++++++++++--- .../peertube/PeertubeStreamExtractorTest.java | 9 ++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java index b67daca13..7e1861f76 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java @@ -112,9 +112,16 @@ public class PeertubeStreamExtractor extends StreamExtractor { } @Override - public long getTimeStamp() { - //TODO fetch timestamp from url if present; - return 0; + public long getTimeStamp() throws ParsingException { + long timestamp = + getTimestampSeconds("((#|&|\\?)start=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s?)"); + + if (timestamp == -2) { + // regex for timestamp was not found + return 0; + } else { + return timestamp; + } } @Override diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorTest.java index 1ecfc7263..f78b96e13 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorTest.java @@ -27,7 +27,9 @@ public class PeertubeStreamExtractorTest { public static class WhatIsPeertube extends DefaultStreamExtractorTest { private static final String ID = "9c9de5e8-0a1e-484a-b099-e80766180a6d"; private static final String INSTANCE = "https://framatube.org"; - private static final String URL = INSTANCE + BASE_URL + ID; + private static final int TIMESTAMP_MINUTE = 1; + private static final int TIMESTAMP_SECOND = 21; + private static final String URL = INSTANCE + BASE_URL + ID + "?start=" + TIMESTAMP_MINUTE + "m" + TIMESTAMP_SECOND + "s"; private static StreamExtractor extractor; @BeforeClass @@ -48,7 +50,7 @@ public class PeertubeStreamExtractorTest { @Override public StreamingService expectedService() { return PeerTube; } @Override public String expectedName() { return "What is PeerTube?"; } @Override public String expectedId() { return ID; } - @Override public String expectedUrlContains() { return BASE_URL + ID; } + @Override public String expectedUrlContains() { return INSTANCE + BASE_URL + ID; } @Override public String expectedOriginalUrlContains() { return URL; } @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } @@ -74,6 +76,7 @@ public class PeertubeStreamExtractorTest { + "**Video sources**: https://gitlab.gnome.org/Jehan/what-is-peertube/"); } @Override public long expectedLength() { return 113; } + @Override public long expectedTimestamp() { return TIMESTAMP_MINUTE*60 + TIMESTAMP_SECOND; } @Override public long expectedViewCountAtLeast() { return 38600; } @Nullable @Override public String expectedUploadDate() { return "2018-10-01 12:52:46.396"; } // GMT (!) @Nullable @Override public String expectedTextualUploadDate() { return "2018-10-01T10:52:46.396Z"; } @@ -103,7 +106,7 @@ public class PeertubeStreamExtractorTest { @Override public StreamingService expectedService() { return PeerTube; } @Override public String expectedName() { return "A DPR Combatant Describes how Orders are Given through Russian Officers"; } @Override public String expectedId() { return ID; } - @Override public String expectedUrlContains() { return BASE_URL + ID; } + @Override public String expectedUrlContains() { return URL; } @Override public String expectedOriginalUrlContains() { return URL; } @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; }