From 9a7a224a545e0dd5036b14e7e7a83e923be03d6a Mon Sep 17 00:00:00 2001 From: vkay94 Date: Sat, 12 Dec 2020 10:24:55 +0100 Subject: [PATCH] Add tests for stream segments --- .../services/DefaultStreamExtractorTest.java | 8 ++ .../MediaCCCStreamExtractorTest.java | 1 + .../peertube/PeertubeStreamExtractorTest.java | 1 + .../SoundcloudStreamExtractorTest.java | 1 + .../YoutubeStreamExtractorDefaultTest.java | 94 ++++++++++++++++++- 5 files changed, 104 insertions(+), 1 deletion(-) diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java index 837ce603..b3a1a0a8 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java @@ -66,6 +66,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest expectedTags() { return Collections.emptyList(); } // default: no tags public String expectedSupportInfo() { return ""; } // default: no support info available + public int expectedStreamSegmentsCount() { return -1; } // return 0 or greater to test (default is -1 to ignore) @Test @Override @@ -379,4 +380,11 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest= 0) { + assertEquals(expectedStreamSegmentsCount(), extractor().getStreamSegments().size()); + } + } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java index ec962cb2..708ced7f 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java @@ -57,6 +57,7 @@ public class MediaCCCStreamExtractorTest { @Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasFrames() { return false; } @Override public List expectedTags() { return Arrays.asList("gpn18", "105"); } + @Override public int expectedStreamSegmentsCount() { return 0; } @Override @Test 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 f8c72957..e4e36fe0 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 @@ -92,6 +92,7 @@ public class PeertubeStreamExtractorTest { @Override public String expectedLicence() { return "Attribution - Share Alike"; } @Override public Locale expectedLanguageInfo() { return Locale.forLanguageTag("en"); } @Override public List expectedTags() { return Arrays.asList("framasoft", "peertube"); } + @Override public int expectedStreamSegmentsCount() { return 0; } } public static class AgeRestricted extends DefaultStreamExtractorTest { diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java index 6e386b1d..687feb4c 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java @@ -55,6 +55,7 @@ public class SoundcloudStreamExtractorTest { @Override public boolean expectedHasVideoStreams() { return false; } @Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasFrames() { return false; } + @Override public int expectedStreamSegmentsCount() { return 0; } } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java index cc627f7f..8c202287 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java @@ -9,6 +9,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.stream.StreamExtractor; +import org.schabi.newpipe.extractor.stream.StreamSegment; import org.schabi.newpipe.extractor.stream.StreamType; import java.util.Arrays; @@ -16,7 +17,7 @@ import java.util.List; import javax.annotation.Nullable; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ServiceList.YouTube; /* @@ -96,6 +97,7 @@ public class YoutubeStreamExtractorDefaultTest { @Nullable @Override public String expectedTextualUploadDate() { return "2019-08-24"; } @Override public long expectedLikeCountAtLeast() { return 5212900; } @Override public long expectedDislikeCountAtLeast() { return 30600; } + @Override public int expectedStreamSegmentsCount() { return 0; } } public static class DescriptionTestUnboxing extends DefaultStreamExtractorTest { @@ -166,4 +168,94 @@ public class YoutubeStreamExtractorDefaultTest { @Override public long expectedLikeCountAtLeast() { return -1; } @Override public long expectedDislikeCountAtLeast() { return -1; } } + + public static class StreamSegmentsTestOstCollection extends DefaultStreamExtractorTest { + // StreamSegment example with single macro-makers panel + private static final String ID = "2RYrHwnLHw0"; + private static final String URL = BASE_URL + ID; + private static StreamExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance()); + extractor = YouTube.getStreamExtractor(URL); + extractor.fetchPage(); + } + + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "1 Hour - Most Epic Anime Mix - Battle Anime OST"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return BASE_URL + ID; } + @Override public String expectedOriginalUrlContains() { return URL; } + + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "MathCaires"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UChFoHg6IT18SCqiwCp_KY7Q"; } + @Override public List expectedDescriptionContains() { + return Arrays.asList("soundtracks", "9:49", "YouSeeBIGGIRLTT"); + } + @Override public long expectedLength() { return 3889; } + @Override public long expectedViewCountAtLeast() { return 2463261; } + @Nullable @Override public String expectedUploadDate() { return "2019-06-26 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2019-06-26"; } + @Override public long expectedLikeCountAtLeast() { return 32100; } + @Override public long expectedDislikeCountAtLeast() { return 750; } + @Override public boolean expectedHasSubtitles() { return false; } + + @Override public int expectedStreamSegmentsCount() { return 17; } + @Test + public void testStreamSegment() throws Exception { + final StreamSegment segment = extractor.getStreamSegments().get(3); + assertEquals(589, segment.getStartTimeSeconds()); + assertEquals("Attack on Titan S2 - YouSeeBIGGIRLTT", segment.getTitle()); + assertEquals(BASE_URL + ID + "?t=589", segment.getUrl()); + assertNotNull(segment.getPreviewUrl()); + } + } + + public static class StreamSegmentsTestMaiLab extends DefaultStreamExtractorTest { + // StreamSegment example with macro-makers panel and transcription panel + private static final String ID = "ud9d5cMDP_0"; + private static final String URL = BASE_URL + ID; + private static StreamExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance()); + extractor = YouTube.getStreamExtractor(URL); + extractor.fetchPage(); + } + + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "Vitamin D wissenschaftlich gepr\u00fcft"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return BASE_URL + ID; } + @Override public String expectedOriginalUrlContains() { return URL; } + + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "maiLab"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCyHDQ5C6z1NDmJ4g6SerW8g"; } + @Override public List expectedDescriptionContains() { + return Arrays.asList("Vitamin", "2:44", "Was ist Vitamin D?"); + } + @Override public long expectedLength() { return 1010; } + @Override public long expectedViewCountAtLeast() { return 815500; } + @Nullable @Override public String expectedUploadDate() { return "2020-11-18 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2020-11-18"; } + @Override public long expectedLikeCountAtLeast() { return 48500; } + @Override public long expectedDislikeCountAtLeast() { return 20000; } + @Override public boolean expectedHasSubtitles() { return true; } + + @Override public int expectedStreamSegmentsCount() { return 7; } + @Test + public void testStreamSegment() throws Exception { + final StreamSegment segment = extractor.getStreamSegments().get(1); + assertEquals(164, segment.getStartTimeSeconds()); + assertEquals("Was ist Vitamin D?", segment.getTitle()); + assertEquals(BASE_URL + ID + "?t=164", segment.getUrl()); + assertNotNull(segment.getPreviewUrl()); + } + } }