From 1d7a86e664717d09e33371bc87c289903b19feb2 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 9 Apr 2020 13:51:47 +0200 Subject: [PATCH] [Test] Add base classes for stream extractor tests Refactor all stream extractor tests to use new base class. Remove check if upload date is in the past: this does not have to hold true: youtube premieres turn up in search results even though they are in the future --- .../newpipe/extractor/ExtractorAsserts.java | 14 +- .../services/BaseStreamExtractorTest.java | 24 ++ .../services/DefaultStreamExtractorTest.java | 286 +++++++++++++++ .../extractor/services/DefaultTests.java | 4 +- .../MediaCCCStreamExtractorTest.java | 214 +++++------ .../PeertubeStreamExtractorDefaultTest.java | 180 ---------- .../peertube/PeertubeStreamExtractorTest.java | 165 +++++++++ .../PeertubeTrendingExtractorTest.java | 4 +- .../SoundcloudChartsExtractorTest.java | 2 +- .../SoundcloudStreamExtractorDefaultTest.java | 163 --------- .../SoundcloudStreamExtractorTest.java | 81 +++++ ...utubeStreamExtractorAgeRestrictedTest.java | 157 ++------- ...utubeStreamExtractorControversialTest.java | 138 ++------ .../YoutubeStreamExtractorDefaultTest.java | 333 ++++++------------ .../YoutubeStreamExtractorLivestreamTest.java | 155 ++------ .../YoutubeStreamExtractorUnlistedTest.java | 169 ++------- 16 files changed, 883 insertions(+), 1206 deletions(-) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorTest.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/ExtractorAsserts.java b/extractor/src/test/java/org/schabi/newpipe/extractor/ExtractorAsserts.java index 1006f7b34..a0a887d7d 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/ExtractorAsserts.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/ExtractorAsserts.java @@ -1,12 +1,16 @@ package org.schabi.newpipe.extractor; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.net.MalformedURLException; import java.net.URL; import java.util.List; -import static org.junit.Assert.*; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class ExtractorAsserts { public static void assertEmptyErrors(String message, List errors) { @@ -56,4 +60,8 @@ public class ExtractorAsserts { assertTrue(message, stringToCheck.isEmpty()); } } + + public static void assertAtLeast(long expected, long actual) { + assertTrue(actual + " is not at least " + expected, actual >= expected); + } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java new file mode 100644 index 000000000..fb555a033 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java @@ -0,0 +1,24 @@ +package org.schabi.newpipe.extractor.services; + +public interface BaseStreamExtractorTest extends BaseExtractorTest { + void testStreamType() throws Exception; + void testUploaderName() throws Exception; + void testUploaderUrl() throws Exception; + void testUploaderAvatarUrl() throws Exception; + void testThumbnailUrl() throws Exception; + void testDescription() throws Exception; + void testLength() throws Exception; + void testTimestamp() throws Exception; + void testViewCount() throws Exception; + void testUploadDate() throws Exception; + void testTextualUploadDate() throws Exception; + void testLikeCount() throws Exception; + void testDislikeCount() throws Exception; + void testRelatedStreams() throws Exception; + void testAgeLimit() throws Exception; + void testErrorMessage() throws Exception; + void testAudioStreams() throws Exception; + void testVideoStreams() throws Exception; + void testSubtitles() throws Exception; + void testFrames() throws Exception; +} 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 new file mode 100644 index 000000000..406177f7e --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java @@ -0,0 +1,286 @@ +package org.schabi.newpipe.extractor.services; + +import org.junit.Test; +import org.schabi.newpipe.extractor.MediaFormat; +import org.schabi.newpipe.extractor.localization.DateWrapper; +import org.schabi.newpipe.extractor.stream.AudioStream; +import org.schabi.newpipe.extractor.stream.Description; +import org.schabi.newpipe.extractor.stream.Frameset; +import org.schabi.newpipe.extractor.stream.StreamExtractor; +import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import org.schabi.newpipe.extractor.stream.StreamType; +import org.schabi.newpipe.extractor.stream.SubtitlesStream; +import org.schabi.newpipe.extractor.stream.VideoStream; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.List; +import java.util.TimeZone; + +import javax.annotation.Nullable; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertAtLeast; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestListOfItems; + +/** + * Test for {@link StreamExtractor} + */ +public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest + implements BaseStreamExtractorTest { + + public abstract StreamType expectedStreamType(); + public abstract String expectedUploaderName(); + public abstract String expectedUploaderUrl(); + public abstract List expectedDescriptionContains(); // e.g. for full links + public abstract long expectedLength(); + public long expectedTimestamp() { return 0; }; // default: there is no timestamp + public abstract long expectedViewCountAtLeast(); + @Nullable public abstract String expectedUploadDate(); // format: "yyyy-MM-dd HH:mm:ss.SSS" + @Nullable public abstract String expectedTextualUploadDate(); + public abstract long expectedLikeCountAtLeast(); // return -1 if ratings are disabled + public abstract long expectedDislikeCountAtLeast(); // return -1 if ratings are disabled + public boolean expectedHasRelatedStreams() { return true; } // default: there are related videos + public int expectedAgeLimit() { return StreamExtractor.NO_AGE_LIMIT; } // default: no limit + @Nullable public String expectedErrorMessage() { return null; } // default: no error message + public boolean expectedHasVideoStreams() { return true; } // default: there are video streams + public boolean expectedHasAudioStreams() { return true; } // default: there are audio streams + public boolean expectedHasSubtitles() { return true; } // default: there are subtitles streams + public boolean expectedHasFrames() { return true; } // default: there are frames + + @Test + @Override + public void testStreamType() throws Exception { + assertEquals(expectedStreamType(), extractor().getStreamType()); + } + + @Test + @Override + public void testUploaderName() throws Exception { + assertEquals(expectedUploaderName(), extractor().getUploaderName()); + } + + @Test + @Override + public void testUploaderUrl() throws Exception { + final String uploaderUrl = extractor().getUploaderUrl(); + assertIsSecureUrl(uploaderUrl); + assertEquals(expectedUploaderUrl(), uploaderUrl); + } + + @Test + @Override + public void testUploaderAvatarUrl() throws Exception { + assertIsSecureUrl(extractor().getUploaderAvatarUrl()); + } + + @Test + @Override + public void testThumbnailUrl() throws Exception { + assertIsSecureUrl(extractor().getThumbnailUrl()); + } + + @Test + @Override + public void testDescription() throws Exception { + final Description description = extractor().getDescription(); + assertNotNull(description); + assertFalse("description is empty", description.getContent().isEmpty()); + + for (String s : expectedDescriptionContains()) { + assertThat(description.getContent(), containsString(s)); + } + } + + @Test + @Override + public void testLength() throws Exception { + assertEquals(expectedLength(), extractor().getLength()); + } + + @Test + @Override + public void testTimestamp() throws Exception { + assertEquals(expectedTimestamp(), extractor().getTimeStamp()); + } + + @Test + @Override + public void testViewCount() throws Exception { + assertAtLeast(expectedViewCountAtLeast(), extractor().getViewCount()); + } + + @Test + @Override + public void testUploadDate() throws Exception { + final DateWrapper dateWrapper = extractor().getUploadDate(); + + if (expectedUploadDate() == null) { + assertNull(dateWrapper); + } else { + assertNotNull(dateWrapper); + + final Calendar expectedDate = Calendar.getInstance(); + final Calendar actualDate = dateWrapper.date(); + expectedDate.setTimeZone(TimeZone.getTimeZone("GMT")); + actualDate.setTimeZone(TimeZone.getTimeZone("GMT")); + + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); + expectedDate.setTime(sdf.parse(expectedUploadDate())); + assertEquals(expectedDate, actualDate); + } + } + + @Test + @Override + public void testTextualUploadDate() throws Exception { + assertEquals(expectedTextualUploadDate(), extractor().getTextualUploadDate()); + } + + @Test + @Override + public void testLikeCount() throws Exception { + if (expectedLikeCountAtLeast() == -1) { + assertEquals(-1, extractor().getLikeCount()); + } else { + assertAtLeast(expectedLikeCountAtLeast(), extractor().getLikeCount()); + } + } + + @Test + @Override + public void testDislikeCount() throws Exception { + if (expectedDislikeCountAtLeast() == -1) { + assertEquals(-1, extractor().getDislikeCount()); + } else { + assertAtLeast(expectedDislikeCountAtLeast(), extractor().getDislikeCount()); + } + } + + @Test + @Override + public void testRelatedStreams() throws Exception { + final StreamInfoItemsCollector relatedStreams = extractor().getRelatedStreams(); + + if (expectedHasRelatedStreams()) { + defaultTestListOfItems(extractor().getService(), relatedStreams.getItems(), + relatedStreams.getErrors()); + } else { + assertNull(relatedStreams); + } + } + + @Test + @Override + public void testAgeLimit() throws Exception { + assertEquals(expectedAgeLimit(), extractor().getAgeLimit()); + } + + @Test + @Override + public void testErrorMessage() throws Exception { + assertEquals(expectedErrorMessage(), extractor().getErrorMessage()); + } + + @Test + @Override + public void testVideoStreams() throws Exception { + List videoStreams = extractor().getVideoStreams(); + final List videoOnlyStreams = extractor().getVideoOnlyStreams(); + assertNotNull(videoStreams); + assertNotNull(videoOnlyStreams); + videoStreams.addAll(videoOnlyStreams); + + if (expectedHasVideoStreams()) { + assertFalse(videoStreams.isEmpty()); + + for (VideoStream stream : videoStreams) { + assertIsSecureUrl(stream.getUrl()); + assertFalse(stream.getResolution().isEmpty()); + + int formatId = stream.getFormatId(); + assertTrue("format id does not fit a video stream: " + formatId, + 0 <= formatId && formatId < 0x100); + } + } else { + assertTrue(videoStreams.isEmpty()); + } + } + + @Test + @Override + public void testAudioStreams() throws Exception { + final List audioStreams = extractor().getAudioStreams(); + assertNotNull(audioStreams); + + if (expectedHasAudioStreams()) { + assertFalse(audioStreams.isEmpty()); + + for (AudioStream stream : audioStreams) { + assertIsSecureUrl(stream.getUrl()); + + int formatId = stream.getFormatId(); + assertTrue("format id does not fit an audio stream: " + formatId, + 0x100 <= formatId && formatId < 0x1000); + } + } else { + assertTrue(audioStreams.isEmpty()); + } + } + + @Test + @Override + public void testSubtitles() throws Exception { + List subtitles = extractor().getSubtitlesDefault(); + assertNotNull(subtitles); + + if (expectedHasSubtitles()) { + assertFalse(subtitles.isEmpty()); + + for (SubtitlesStream stream : subtitles) { + assertIsSecureUrl(stream.getUrl()); + + int formatId = stream.getFormatId(); + assertTrue("format id does not fit an audio stream: " + formatId, + 0x1000 <= formatId && formatId < 0x10000); + } + } else { + assertTrue(subtitles.isEmpty()); + + MediaFormat[] formats = {MediaFormat.VTT, MediaFormat.TTML, MediaFormat.TRANSCRIPT1, + MediaFormat.TRANSCRIPT2, MediaFormat.TRANSCRIPT3, MediaFormat.SRT}; + for (MediaFormat format : formats) { + subtitles = extractor().getSubtitles(format); + assertNotNull(subtitles); + assertTrue(subtitles.isEmpty()); + } + } + } + + @Test + @Override + public void testFrames() throws Exception { + final List frames = extractor().getFrames(); + assertNotNull(frames); + + if (expectedHasFrames()) { + assertFalse(frames.isEmpty()); + for (final Frameset f : frames) { + for (final String url : f.getUrls()) { + assertIsValidUrl(url); + assertIsSecureUrl(url); + } + } + } else { + assertTrue(frames.isEmpty()); + } + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java index a335b0eca..d2b9ca4ae 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java @@ -10,7 +10,6 @@ import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import java.util.Calendar; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -42,7 +41,7 @@ public final class DefaultTests { StreamInfoItem streamInfoItem = (StreamInfoItem) item; assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName()); -// assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl()); + // assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl()); final String uploaderUrl = streamInfoItem.getUploaderUrl(); if (!isNullOrEmpty(uploaderUrl)) { assertIsSecureUrl(uploaderUrl); @@ -54,7 +53,6 @@ public final class DefaultTests { if (!isNullOrEmpty(streamInfoItem.getTextualUploadDate())) { final DateWrapper uploadDate = streamInfoItem.getUploadDate(); assertNotNull("No parsed upload date", uploadDate); - assertTrue("Upload date not in the past", uploadDate.date().before(Calendar.getInstance())); } } else if (item instanceof ChannelInfoItem) { 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 95c882290..6a4c4c0e2 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 @@ -1,204 +1,148 @@ package org.schabi.newpipe.extractor.services.media_ccc; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.schabi.newpipe.DownloaderTestImpl; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCStreamExtractor; -import org.schabi.newpipe.extractor.stream.AudioStream; -import org.schabi.newpipe.extractor.stream.VideoStream; +import org.schabi.newpipe.extractor.stream.StreamExtractor; +import org.schabi.newpipe.extractor.stream.StreamType; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; +import java.util.Arrays; import java.util.List; -import static java.util.Objects.requireNonNull; +import javax.annotation.Nullable; + import static junit.framework.TestCase.assertEquals; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.MediaCCC; /** * Test {@link MediaCCCStreamExtractor} */ public class MediaCCCStreamExtractorTest { - public static class Gpn18Tmux { - private static MediaCCCStreamExtractor extractor; + private static final String BASE_URL = "https://media.ccc.de/v/"; + + public static class Gpn18Tmux extends DefaultStreamExtractorTest { + private static final String ID = "gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht"; + private static final String URL = BASE_URL + ID; + private static StreamExtractor extractor; @BeforeClass - public static void setUpClass() throws Exception { + public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - - extractor = (MediaCCCStreamExtractor) MediaCCC.getStreamExtractor("https://media.ccc.de/v/gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht"); + extractor = MediaCCC.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testServiceId() throws Exception { - assertEquals(2, extractor.getServiceId()); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return MediaCCC; } + @Override public String expectedName() { return "tmux - Warum ein schwarzes Fenster am Bildschirm reicht"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return URL; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testName() throws Exception { - assertEquals("tmux - Warum ein schwarzes Fenster am Bildschirm reicht", extractor.getName()); - } + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "gpn18"; } + @Override public String expectedUploaderUrl() { return "https://media.ccc.de/c/gpn18"; } + @Override public List expectedDescriptionContains() { return Arrays.asList("SSH-Sessions", "\"Terminal Multiplexer\""); } + @Override public long expectedLength() { return 3097; } + @Override public long expectedViewCountAtLeast() { return 2380; } + @Nullable @Override public String expectedUploadDate() { return "2018-05-11 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2018-05-11T02:00:00.000+02:00"; } + @Override public long expectedLikeCountAtLeast() { return -1; } + @Override public long expectedDislikeCountAtLeast() { return -1; } + @Override public boolean expectedHasSubtitles() { return false; } + @Override public boolean expectedHasFrames() { return false; } + @Override @Test - public void testId() throws Exception { - assertEquals("gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht", extractor.getId()); - } - - @Test - public void testUrl() throws Exception { - assertIsSecureUrl(extractor.getUrl()); - assertEquals("https://media.ccc.de/public/events/gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht", extractor.getUrl()); - } - - @Test - public void testOriginalUrl() throws Exception { - assertIsSecureUrl(extractor.getOriginalUrl()); - assertEquals("https://media.ccc.de/v/gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht", extractor.getOriginalUrl()); - } - - @Test - public void testThumbnail() throws Exception { - assertIsSecureUrl(extractor.getThumbnailUrl()); + public void testThumbnailUrl() throws Exception { + super.testThumbnailUrl(); assertEquals("https://static.media.ccc.de/media/events/gpn/gpn18/105-hd.jpg", extractor.getThumbnailUrl()); } - @Test - public void testUploaderName() throws Exception { - assertEquals("gpn18", extractor.getUploaderName()); - } - - @Test - public void testUploaderUrl() throws Exception { - assertIsSecureUrl(extractor.getUploaderUrl()); - assertEquals("https://media.ccc.de/public/conferences/gpn18", extractor.getUploaderUrl()); - } - + @Override @Test public void testUploaderAvatarUrl() throws Exception { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); + super.testUploaderAvatarUrl(); assertEquals("https://static.media.ccc.de/media/events/gpn/gpn18/logo.png", extractor.getUploaderAvatarUrl()); } + @Override @Test public void testVideoStreams() throws Exception { - List videoStreamList = extractor.getVideoStreams(); - assertEquals(4, videoStreamList.size()); - for (VideoStream stream : videoStreamList) { - assertIsSecureUrl(stream.getUrl()); - } + super.testVideoStreams(); + assertEquals(4, extractor.getVideoStreams().size()); } + @Override @Test public void testAudioStreams() throws Exception { - List audioStreamList = extractor.getAudioStreams(); - assertEquals(2, audioStreamList.size()); - for (AudioStream stream : audioStreamList) { - assertIsSecureUrl(stream.getUrl()); - } - } - - @Test - public void testGetTextualUploadDate() throws ParsingException { - Assert.assertEquals("2018-05-11T02:00:00.000+02:00", extractor.getTextualUploadDate()); - } - - @Test - public void testGetUploadDate() throws ParsingException, ParseException { - final Calendar instance = Calendar.getInstance(); - instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2018-05-11")); - assertEquals(instance, requireNonNull(extractor.getUploadDate()).date()); + super.testAudioStreams(); + assertEquals(2, extractor.getAudioStreams().size()); } } - public static class _36c3PrivacyMessaging { - private static MediaCCCStreamExtractor extractor; + public static class _36c3PrivacyMessaging extends DefaultStreamExtractorTest { + private static final String ID = "36c3-10565-what_s_left_for_private_messaging"; + private static final String URL = BASE_URL + ID; + private static StreamExtractor extractor; @BeforeClass - public static void setUpClass() throws Exception { + public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (MediaCCCStreamExtractor) MediaCCC.getStreamExtractor("https://media.ccc.de/v/36c3-10565-what_s_left_for_private_messaging"); + extractor = MediaCCC.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testName() throws Exception { - assertEquals("What's left for private messaging?", extractor.getName()); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return MediaCCC; } + @Override public String expectedName() { return "What's left for private messaging?"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return URL; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testId() throws Exception { - assertEquals("36c3-10565-what_s_left_for_private_messaging", extractor.getId()); - } + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "36c3"; } + @Override public String expectedUploaderUrl() { return "https://media.ccc.de/c/36c3"; } + @Override public List expectedDescriptionContains() { return Arrays.asList("WhatsApp", "Signal"); } + @Override public long expectedLength() { return 3603; } + @Override public long expectedViewCountAtLeast() { return 2380; } + @Nullable @Override public String expectedUploadDate() { return "2020-01-11 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2020-01-11T01:00:00.000+01:00"; } + @Override public long expectedLikeCountAtLeast() { return -1; } + @Override public long expectedDislikeCountAtLeast() { return -1; } + @Override public boolean expectedHasSubtitles() { return false; } + @Override public boolean expectedHasFrames() { return false; } + @Override @Test - public void testUrl() throws Exception { - assertIsSecureUrl(extractor.getUrl()); - assertEquals("https://media.ccc.de/public/events/36c3-10565-what_s_left_for_private_messaging", extractor.getUrl()); - } - - @Test - public void testOriginalUrl() throws Exception { - assertIsSecureUrl(extractor.getOriginalUrl()); - assertEquals("https://media.ccc.de/v/36c3-10565-what_s_left_for_private_messaging", extractor.getOriginalUrl()); - } - - @Test - public void testThumbnail() throws Exception { - assertIsSecureUrl(extractor.getThumbnailUrl()); + public void testThumbnailUrl() throws Exception { + super.testThumbnailUrl(); assertEquals("https://static.media.ccc.de/media/congress/2019/10565-hd.jpg", extractor.getThumbnailUrl()); } - @Test - public void testUploaderName() throws Exception { - assertEquals("36c3", extractor.getUploaderName()); - } - - @Test - public void testUploaderUrl() throws Exception { - assertIsSecureUrl(extractor.getUploaderUrl()); - assertEquals("https://media.ccc.de/public/conferences/36c3", extractor.getUploaderUrl()); - } - + @Override @Test public void testUploaderAvatarUrl() throws Exception { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); + super.testUploaderAvatarUrl(); assertEquals("https://static.media.ccc.de/media/congress/2019/logo.png", extractor.getUploaderAvatarUrl()); } + @Override @Test public void testVideoStreams() throws Exception { - List videoStreamList = extractor.getVideoStreams(); - assertEquals(8, videoStreamList.size()); - for (VideoStream stream : videoStreamList) { - assertIsSecureUrl(stream.getUrl()); - } + super.testVideoStreams(); + assertEquals(8, extractor.getVideoStreams().size()); } + @Override @Test public void testAudioStreams() throws Exception { - List audioStreamList = extractor.getAudioStreams(); - assertEquals(2, audioStreamList.size()); - for (AudioStream stream : audioStreamList) { - assertIsSecureUrl(stream.getUrl()); - } - } - - @Test - public void testGetTextualUploadDate() throws ParsingException { - Assert.assertEquals("2020-01-11T01:00:00.000+01:00", extractor.getTextualUploadDate()); - } - - @Test - public void testGetUploadDate() throws ParsingException, ParseException { - final Calendar instance = Calendar.getInstance(); - instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-11")); - assertEquals(instance, requireNonNull(extractor.getUploadDate()).date()); + super.testAudioStreams(); + assertEquals(2, extractor.getAudioStreams().size()); } } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java deleted file mode 100644 index c3d8c7169..000000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java +++ /dev/null @@ -1,180 +0,0 @@ -package org.schabi.newpipe.extractor.services.peertube; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.schabi.newpipe.DownloaderTestImpl; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeStreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; -import org.schabi.newpipe.extractor.stream.StreamType; - -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Locale; -import java.util.TimeZone; - -import static java.util.Objects.requireNonNull; -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; -import static org.schabi.newpipe.extractor.ServiceList.PeerTube; - -/** - * Test for {@link StreamExtractor} - */ -public class PeertubeStreamExtractorDefaultTest { - private static PeertubeStreamExtractor extractor; - private static final String expectedLargeDescription = "**[Want to help to translate this video?](https://weblate.framasoft.org/projects/what-is-peertube-video/)**\r\n\r\n**Take back the control of your videos! [#JoinPeertube](https://joinpeertube.org)**\r\n*A decentralized video hosting network, based on free/libre software!*\r\n\r\n**Animation Produced by:** [LILA](https://libreart.info) - [ZeMarmot Team](https://film.zemarmot.net)\r\n*Directed by* Aryeom\r\n*Assistant* Jehan\r\n**Licence**: [CC-By-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)\r\n\r\n**Sponsored by** [Framasoft](https://framasoft.org)\r\n\r\n**Music**: [Red Step Forward](http://play.dogmazic.net/song.php?song_id=52491) - CC-By Ken Bushima\r\n\r\n**Movie Clip**: [Caminades 3: Llamigos](http://www.caminandes.com/) CC-By Blender Institute\r\n\r\n**Video sources**: https://gitlab.gnome.org/Jehan/what-is-peertube/"; - private static final String expectedSmallDescription = "https://www.kickstarter.com/projects/1587081065/nothing-to-hide-the-documentary"; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(DownloaderTestImpl.getInstance()); - // setting instance might break test when running in parallel - PeerTube.setInstance(new PeertubeInstance("https://framatube.org", "FramaTube")); - extractor = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d"); - extractor.fetchPage(); - } - - @Test - public void testGetUploadDate() throws ParsingException, ParseException { - final Calendar instance = Calendar.getInstance(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'"); - sdf.setTimeZone(TimeZone.getTimeZone("GMT")); - instance.setTime(sdf.parse("2018-10-01T10:52:46.396Z")); - assertEquals(instance, requireNonNull(extractor.getUploadDate()).date()); - - } - - @Test - public void testGetInvalidTimeStamp() throws ParsingException { - assertTrue(extractor.getTimeStamp() + "", - extractor.getTimeStamp() <= 0); - } - - @Test - public void testGetTitle() throws ParsingException { - assertEquals("What is PeerTube?", extractor.getName()); - } - - @Test - public void testGetLargeDescription() throws ParsingException { - assertEquals(expectedLargeDescription, extractor.getDescription().getContent()); - } - - @Test - public void testGetEmptyDescription() throws Exception { - PeertubeStreamExtractor extractorEmpty = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://framatube.org/api/v1/videos/d5907aad-2252-4207-89ec-a4b687b9337d"); - extractorEmpty.fetchPage(); - assertEquals("", extractorEmpty.getDescription().getContent()); - } - - @Test - public void testGetSmallDescription() throws Exception { - PeerTube.setInstance(new PeertubeInstance("https://peertube.cpy.re", "PeerTube test server")); - PeertubeStreamExtractor extractorSmall = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://peertube.cpy.re/videos/watch/d2a5ec78-5f85-4090-8ec5-dc1102e022ea"); - extractorSmall.fetchPage(); - assertEquals(expectedSmallDescription, extractorSmall.getDescription().getContent()); - } - - @Test - public void testGetUploaderName() throws ParsingException { - assertEquals("Framasoft", extractor.getUploaderName()); - } - - @Test - public void testGetUploaderUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderUrl()); - assertEquals("https://framatube.org/api/v1/accounts/framasoft@framatube.org", extractor.getUploaderUrl()); - } - - @Test - public void testGetUploaderAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testGetSubChannelName() throws ParsingException { - assertEquals("Les vidéos de Framasoft", extractor.getSubChannelName()); - } - - @Test - public void testGetSubChannelUrl() throws ParsingException { - assertIsSecureUrl(extractor.getSubChannelUrl()); - assertEquals("https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8", extractor.getSubChannelUrl()); - } - - @Test - public void testGetSubChannelAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getSubChannelAvatarUrl()); - } - - @Test - public void testGetLength() throws ParsingException { - assertEquals(113, extractor.getLength()); - } - - @Test - public void testGetViewCount() throws ParsingException { - assertTrue(Long.toString(extractor.getViewCount()), - extractor.getViewCount() > 10); - } - - @Test - public void testGetThumbnailUrl() throws ParsingException { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Test - public void testGetVideoStreams() throws IOException, ExtractionException { - assertFalse(extractor.getVideoStreams().isEmpty()); - } - - @Test - public void testStreamType() throws ParsingException { - assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM); - } - - @Ignore - @Test - public void testGetRelatedVideos() throws ExtractionException, IOException { - StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); - assertFalse(relatedVideos.getItems().isEmpty()); - assertTrue(relatedVideos.getErrors().isEmpty()); - } - - @Test - public void testGetSubtitlesListDefault() throws IOException, ExtractionException { - assertFalse(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetSubtitlesList() throws IOException, ExtractionException { - assertFalse(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetAgeLimit() throws ExtractionException, IOException { - assertEquals(0, extractor.getAgeLimit()); - PeertubeStreamExtractor ageLimit = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://nocensoring.net/videos/embed/dbd8e5e1-c527-49b6-b70c-89101dbb9c08"); - ageLimit.fetchPage(); - assertEquals(18, ageLimit.getAgeLimit()); - } - - @Test - public void testGetSupportInformation() throws ExtractionException, IOException { - PeertubeStreamExtractor supportInfoExtractor = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://framatube.org/videos/watch/ee408ec8-07cd-4e35-b884-fb681a4b9d37"); - supportInfoExtractor.fetchPage(); - assertEquals("https://utip.io/chatsceptique", supportInfoExtractor.getSupportInfo()); - } - - @Test - public void testGetLanguageInformation() throws ParsingException { - assertEquals(new Locale("en"), extractor.getLanguageInfo()); - } -} 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 new file mode 100644 index 000000000..bddb75bd4 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorTest.java @@ -0,0 +1,165 @@ +package org.schabi.newpipe.extractor.services.peertube; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.DownloaderTestImpl; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +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.StreamType; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import javax.annotation.Nullable; + +import static org.junit.Assert.assertEquals; +import static org.schabi.newpipe.extractor.ServiceList.PeerTube; + +public class PeertubeStreamExtractorTest { + private static final String BASE_URL = "/videos/watch/"; + + 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 StreamExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance()); + // setting instance might break test when running in parallel (!) + PeerTube.setInstance(new PeertubeInstance(INSTANCE, "FramaTube")); + extractor = PeerTube.getStreamExtractor(URL); + extractor.fetchPage(); + } + + @Test + public void testGetLanguageInformation() throws ParsingException { + assertEquals(new Locale("en"), extractor.getLanguageInfo()); + } + + @Override public StreamExtractor extractor() { return extractor; } + @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 expectedOriginalUrlContains() { return URL; } + + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "Framasoft"; } + @Override public String expectedUploaderUrl() { return "https://framatube.org/accounts/framasoft"; } + @Override public List expectedDescriptionContains() { // CRLF line ending + return Arrays.asList("**[Want to help to translate this video?](https://weblate.framasoft.org/projects/what-is-peertube-video/)**\r\n" + + "\r\n" + + "**Take back the control of your videos! [#JoinPeertube](https://joinpeertube.org)**\r\n" + + "*A decentralized video hosting network, based on free/libre software!*\r\n" + + "\r\n" + + "**Animation Produced by:** [LILA](https://libreart.info) - [ZeMarmot Team](https://film.zemarmot.net)\r\n" + + "*Directed by* Aryeom\r\n" + + "*Assistant* Jehan\r\n" + + "**Licence**: [CC-By-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)\r\n" + + "\r\n" + + "**Sponsored by** [Framasoft](https://framasoft.org)\r\n" + + "\r\n" + + "**Music**: [Red Step Forward](http://play.dogmazic.net/song.php?song_id=52491) - CC-By Ken Bushima\r\n" + + "\r\n" + + "**Movie Clip**: [Caminades 3: Llamigos](http://www.caminandes.com/) CC-By Blender Institute\r\n" + + "\r\n" + + "**Video sources**: https://gitlab.gnome.org/Jehan/what-is-peertube/"); + } + @Override public long expectedLength() { return 113; } + @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"; } + @Override public long expectedLikeCountAtLeast() { return 120; } + @Override public long expectedDislikeCountAtLeast() { return 0; } + @Override public boolean expectedHasAudioStreams() { return false; } + @Override public boolean expectedHasFrames() { return false; } + + } + + public static class AgeRestricted extends DefaultStreamExtractorTest { + private static final String ID = "0d501633-f2d9-4476-87c6-71f1c02402a4"; + private static final String INSTANCE = "https://peertube.co.uk"; + private static final String URL = INSTANCE + BASE_URL + ID; + private static StreamExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance());; + // setting instance might break test when running in parallel (!) + PeerTube.setInstance(new PeertubeInstance(INSTANCE)); + extractor = PeerTube.getStreamExtractor(URL); + extractor.fetchPage(); + } + + @Override public StreamExtractor extractor() { return extractor; } + @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 expectedOriginalUrlContains() { return URL; } + + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "Tomas Berezovskiy"; } + @Override public String expectedUploaderUrl() { return "https://peertube.iriseden.eu/accounts/tomas_berezovskiy"; } + @Override public List expectedDescriptionContains() { // LF line ending + return Arrays.asList("https://en.informnapalm.org/dpr-combatant-describes-orders-given-russian-officers/ " + + " The InformNapalm team received another video of a separatist prisoner of war telling about his " + + "activities in `Dontesk People’s Republic’ (DPR) structures. The video is old, as the interrogation" + + " date is September, but it is the situation described is still relevant and interesting today. In " + + "this recording the combatant re-tells how he came to be recruited into the DPR forces, and how " + + "they are operating under Russian military command. He expresses remorse for his stupidity. Perhaps" + + " he is just saying what he thinks his interrogator wants to hear, perhaps he is speaking from a " + + "new understanding?\n" + + "\n" + + "The video contains a lot of cut and paste (stitching) in places where intelligence data or valuable" + + " information has been deleted because it cannot be shared publically. We trust you will understand " + + "this necessity."); + } + @Override public long expectedLength() { return 512; } + @Override public long expectedViewCountAtLeast() { return 7; } + @Nullable @Override public String expectedUploadDate() { return "2019-10-22 08:16:48.982"; } // GMT (!) + @Nullable @Override public String expectedTextualUploadDate() { return "2019-10-22T06:16:48.982Z"; } + @Override public long expectedLikeCountAtLeast() { return 3; } + @Override public long expectedDislikeCountAtLeast() { return 0; } + @Override public int expectedAgeLimit() { return 18; } + @Override public boolean expectedHasAudioStreams() { return false; } + @Override public boolean expectedHasSubtitles() { return false; } + @Override public boolean expectedHasFrames() { return false; } + } + + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance()); + PeerTube.setInstance(new PeertubeInstance("https://peertube.cpy.re", "PeerTube test server")); + } + + @Test + public void testGetEmptyDescription() throws Exception { + StreamExtractor extractorEmpty = PeerTube.getStreamExtractor("https://framatube.org/api/v1/videos/d5907aad-2252-4207-89ec-a4b687b9337d"); + extractorEmpty.fetchPage(); + assertEquals("", extractorEmpty.getDescription().getContent()); + } + + @Test + public void testGetSmallDescription() throws Exception { + StreamExtractor extractorSmall = PeerTube.getStreamExtractor("https://peertube.cpy.re/videos/watch/d2a5ec78-5f85-4090-8ec5-dc1102e022ea"); + extractorSmall.fetchPage(); + assertEquals("https://www.kickstarter.com/projects/1587081065/nothing-to-hide-the-documentary", extractorSmall.getDescription().getContent()); + } + + @Test + public void testGetSupportInformation() throws ExtractionException, IOException { + StreamExtractor supportInfoExtractor = PeerTube.getStreamExtractor("https://framatube.org/videos/watch/ee408ec8-07cd-4e35-b884-fb681a4b9d37"); + supportInfoExtractor.fetchPage(); + assertEquals("https://utip.io/chatsceptique", supportInfoExtractor.getSupportInfo()); + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java index 60f72f9d1..924dbbc1f 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java @@ -8,8 +8,8 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor; -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ServiceList.*; +import static org.junit.Assert.assertEquals; +import static org.schabi.newpipe.extractor.ServiceList.PeerTube; import static org.schabi.newpipe.extractor.services.DefaultTests.*; public class PeertubeTrendingExtractorTest { diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java index 8abfb4d3f..54c48431b 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java @@ -8,7 +8,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChartsExtractor; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; import static org.schabi.newpipe.extractor.services.DefaultTests.*; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java deleted file mode 100644 index 794a1a6b6..000000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java +++ /dev/null @@ -1,163 +0,0 @@ -package org.schabi.newpipe.extractor.services.soundcloud; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.schabi.newpipe.DownloaderTestImpl; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; -import org.schabi.newpipe.extractor.stream.StreamType; - -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.TimeZone; - -import static java.util.Objects.requireNonNull; -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - -/** - * Test for {@link StreamExtractor} - */ -public class SoundcloudStreamExtractorDefaultTest { - - public static class LilUziVertDoWhatIWant { - private static SoundcloudStreamExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (SoundcloudStreamExtractor) SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon"); - extractor.fetchPage(); - } - - @Test - public void testGetInvalidTimeStamp() throws ParsingException { - assertTrue(extractor.getTimeStamp() + "", - extractor.getTimeStamp() <= 0); - } - - @Test - public void testGetValidTimeStamp() throws IOException, ExtractionException { - StreamExtractor extractor = SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69"); - assertEquals("69", extractor.getTimeStamp() + ""); - } - - @Test - public void testGetTitle() throws ParsingException { - assertEquals("Do What I Want [Produced By Maaly Raw + Don Cannon]", extractor.getName()); - } - - @Test - public void testGetDescription() throws ParsingException { - assertEquals("The Perfect LUV Tape®️", extractor.getDescription().getContent()); - } - - @Test - public void testGetUploaderName() throws ParsingException { - assertEquals("Lil Uzi Vert", extractor.getUploaderName()); - } - - @Test - public void testGetLength() throws ParsingException { - assertEquals(175, extractor.getLength()); - } - - @Test - public void testGetViewCount() throws ParsingException { - assertTrue(Long.toString(extractor.getViewCount()), - extractor.getViewCount() > 44227978); - } - - @Test - public void testGetTextualUploadDate() throws ParsingException { - Assert.assertEquals("2016-07-31 18:18:07", extractor.getTextualUploadDate()); - } - - @Test - public void testGetUploadDate() throws ParsingException, ParseException { - final Calendar instance = Calendar.getInstance(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss +0000"); - sdf.setTimeZone(TimeZone.getTimeZone("GMT")); - instance.setTime(sdf.parse("2016/07/31 18:18:07 +0000")); - assertEquals(instance, requireNonNull(extractor.getUploadDate()).date()); - } - - @Test - public void testGetUploaderUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderUrl()); - assertEquals("https://soundcloud.com/liluzivert", extractor.getUploaderUrl()); - } - - @Test - public void testGetThumbnailUrl() throws ParsingException { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Test - public void testGetUploaderAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testGetAudioStreams() throws IOException, ExtractionException { - assertFalse(extractor.getAudioStreams().isEmpty()); - } - - @Test - public void testStreamType() throws ParsingException { - assertTrue(extractor.getStreamType() == StreamType.AUDIO_STREAM); - } - - @Test - public void testGetRelatedVideos() throws ExtractionException, IOException { - StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); - assertFalse(relatedVideos.getItems().isEmpty()); - assertTrue(relatedVideos.getErrors().isEmpty()); - } - - @Test - public void testGetSubtitlesListDefault() throws IOException, ExtractionException { - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetSubtitlesList() throws IOException, ExtractionException { - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitlesDefault().isEmpty()); - } - } - - public static class ContentNotSupported { - @BeforeClass - public static void setUp() { - NewPipe.init(DownloaderTestImpl.getInstance()); - } - - @Test(expected = ContentNotSupportedException.class) - public void hlsAudioStream() throws Exception { - final StreamExtractor extractor = - SoundCloud.getStreamExtractor("https://soundcloud.com/dualipa/cool"); - extractor.fetchPage(); - extractor.getAudioStreams(); - } - - @Test(expected = ContentNotSupportedException.class) - public void bothHlsAndOpusAudioStreams() throws Exception { - final StreamExtractor extractor = - SoundCloud.getStreamExtractor("https://soundcloud.com/lil-baby-4pf/no-sucker"); - extractor.fetchPage(); - extractor.getAudioStreams(); - } - } -} - 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 new file mode 100644 index 000000000..28c8d0b23 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java @@ -0,0 +1,81 @@ +package org.schabi.newpipe.extractor.services.soundcloud; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.DownloaderTestImpl; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; +import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; +import org.schabi.newpipe.extractor.stream.StreamExtractor; +import org.schabi.newpipe.extractor.stream.StreamType; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Nullable; + +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; + +public class SoundcloudStreamExtractorTest { + + public static class LilUziVertDoWhatIWant extends DefaultStreamExtractorTest { + private static final String ID = "do-what-i-want-produced-by-maaly-raw-don-cannon"; + private static final String UPLOADER = "https://soundcloud.com/liluzivert"; + private static final int TIMESTAMP = 69; + private static final String URL = UPLOADER + "/" + ID + "#t=" + TIMESTAMP; + private static StreamExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance()); + extractor = SoundCloud.getStreamExtractor(URL); + extractor.fetchPage(); + } + + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return SoundCloud; } + @Override public String expectedName() { return "Do What I Want [Produced By Maaly Raw + Don Cannon]"; } + @Override public String expectedId() { return "276206960"; } + @Override public String expectedUrlContains() { return UPLOADER + "/" + ID; } + @Override public String expectedOriginalUrlContains() { return URL; } + + @Override public StreamType expectedStreamType() { return StreamType.AUDIO_STREAM; } + @Override public String expectedUploaderName() { return "Lil Uzi Vert"; } + @Override public String expectedUploaderUrl() { return UPLOADER; } + @Override public List expectedDescriptionContains() { return Arrays.asList("The Perfect LUV Tape®"); } + @Override public long expectedLength() { return 175; } + @Override public long expectedTimestamp() { return TIMESTAMP; } + @Override public long expectedViewCountAtLeast() { return 75413600; } + @Nullable @Override public String expectedUploadDate() { return "2016-07-31 18:18:07.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2016-07-31 18:18:07"; } + @Override public long expectedLikeCountAtLeast() { return -1; } + @Override public long expectedDislikeCountAtLeast() { return -1; } + @Override public boolean expectedHasVideoStreams() { return false; } + @Override public boolean expectedHasSubtitles() { return false; } + @Override public boolean expectedHasFrames() { return false; } + } + + public static class ContentNotSupported { + @BeforeClass + public static void setUp() { + NewPipe.init(DownloaderTestImpl.getInstance()); + } + + @Test(expected = ContentNotSupportedException.class) + public void hlsAudioStream() throws Exception { + final StreamExtractor extractor = + SoundCloud.getStreamExtractor("https://soundcloud.com/dualipa/cool"); + extractor.fetchPage(); + extractor.getAudioStreams(); + } + + @Test(expected = ContentNotSupportedException.class) + public void bothHlsAndOpusAudioStreams() throws Exception { + final StreamExtractor extractor = + SoundCloud.getStreamExtractor("https://soundcloud.com/lil-baby-4pf/no-sucker"); + extractor.fetchPage(); + extractor.getAudioStreams(); + } + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java index 95c8aeb43..6844ca2e9 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java @@ -1,144 +1,53 @@ package org.schabi.newpipe.extractor.services.youtube.stream; import org.junit.BeforeClass; -import org.junit.Test; import org.schabi.newpipe.DownloaderTestImpl; -import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.VideoStream; +import org.schabi.newpipe.extractor.stream.StreamType; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; +import java.util.Arrays; import java.util.List; -import static java.util.Objects.requireNonNull; -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import javax.annotation.Nullable; + import static org.schabi.newpipe.extractor.ServiceList.YouTube; -/** - * Test for {@link YoutubeStreamLinkHandlerFactory} - */ -public class YoutubeStreamExtractorAgeRestrictedTest { - public static final String HTTPS = "https://"; - private static YoutubeStreamExtractor extractor; +public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtractorTest { + private static final String ID = "MmBeUZqv1QA"; + private static final int TIMESTAMP = 196; + private static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID + "&t=" + TIMESTAMP; + private static StreamExtractor extractor; @BeforeClass public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=MmBeUZqv1QA"); + extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testGetInvalidTimeStamp() throws ParsingException { - assertTrue(extractor.getTimeStamp() + "", extractor.getTimeStamp() <= 0); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "FINGERING PORNSTARS @ AVN Expo 2017 In Las Vegas!"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return YoutubeStreamExtractorDefaultTest.BASE_URL + ID; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testGetValidTimeStamp() throws IOException, ExtractionException { - StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174"); - assertEquals(extractor.getTimeStamp() + "", "174"); - extractor = YouTube.getStreamExtractor("https://youtube.com/embed/FmG385_uUys?start=174"); - assertEquals(extractor.getTimeStamp() + "", "174"); - } - - @Test - public void testGetAgeLimit() throws ParsingException { - assertEquals(18, extractor.getAgeLimit()); - } - - @Test - public void testGetName() throws ParsingException { - assertNotNull("name is null", extractor.getName()); - assertFalse("name is empty", extractor.getName().isEmpty()); - } - - @Test - public void testGetDescription() throws ParsingException { - assertNotNull(extractor.getDescription()); - assertFalse(extractor.getDescription().getContent().isEmpty()); - } - - @Test - public void testGetUploaderName() throws ParsingException { - assertNotNull(extractor.getUploaderName()); - assertFalse(extractor.getUploaderName().isEmpty()); - } - - @Test - public void testGetLength() throws ParsingException { - assertEquals(1790, extractor.getLength()); - } - - @Test - public void testGetViews() throws ParsingException { - assertTrue(extractor.getViewCount() > 0); - } - - @Test - public void testGetTextualUploadDate() throws ParsingException { - assertEquals("2017-01-25", extractor.getTextualUploadDate()); - } - - @Test - public void testGetUploadDate() throws ParsingException, ParseException { - final Calendar instance = Calendar.getInstance(); - instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2017-01-25")); - assertEquals(instance, requireNonNull(extractor.getUploadDate()).date()); - } - - @Test - public void testGetThumbnailUrl() throws ParsingException { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Test - public void testGetUploaderAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testGetAudioStreams() throws IOException, ExtractionException { - // audio streams are not always necessary - assertFalse(extractor.getAudioStreams().isEmpty()); - } - - @Test - public void testGetVideoStreams() throws IOException, ExtractionException { - List streams = new ArrayList<>(); - streams.addAll(extractor.getVideoStreams()); - streams.addAll(extractor.getVideoOnlyStreams()); - - assertTrue(Integer.toString(streams.size()), streams.size() > 0); - for (VideoStream s : streams) { - assertTrue(s.getUrl(), - s.getUrl().contains(HTTPS)); - assertTrue(s.resolution.length() > 0); - assertTrue(Integer.toString(s.getFormatId()), - 0 <= s.getFormatId() && s.getFormatId() <= 0x100); - } - } - - - @Test - public void testGetSubtitlesListDefault() throws IOException, ExtractionException { - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetSubtitlesList() throws IOException, ExtractionException { - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty()); - } + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "EpicFiveTV"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCuPUHlLP5POZphOIrjrNxiw"; } + @Override public List expectedDescriptionContains() { return Arrays.asList("http://instagram.com/Ruben_Sole", "AVN"); } + @Override public long expectedLength() { return 1790; } + @Override public long expectedTimestamp() { return TIMESTAMP; } + @Override public long expectedViewCountAtLeast() { return 28500000; } + @Nullable @Override public String expectedUploadDate() { return "2017-01-25 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2017-01-25"; } + @Override public long expectedLikeCountAtLeast() { return 149000; } + @Override public long expectedDislikeCountAtLeast() { return 38000; } + @Override public boolean expectedHasRelatedStreams() { return false; } // no related videos (!) + @Override public int expectedAgeLimit() { return 18; } + @Nullable @Override public String expectedErrorMessage() { return "Sign in to confirm your age"; } + @Override public boolean expectedHasSubtitles() { return false; } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java index 915f42ae1..a090460a5 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java @@ -1,134 +1,54 @@ package org.schabi.newpipe.extractor.services.youtube.stream; import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; import org.schabi.newpipe.DownloaderTestImpl; -import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.VideoStream; +import org.schabi.newpipe.extractor.stream.StreamType; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; +import java.util.Arrays; import java.util.List; -import static java.util.Objects.requireNonNull; -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import javax.annotation.Nullable; + import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** * Test for {@link YoutubeStreamLinkHandlerFactory} */ -public class YoutubeStreamExtractorControversialTest { - private static YoutubeStreamExtractor extractor; +public class YoutubeStreamExtractorControversialTest extends DefaultStreamExtractorTest { + private static final String ID = "T4XJQO3qol8"; + private static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID; + private static StreamExtractor extractor; @BeforeClass public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=T4XJQO3qol8"); + extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testGetInvalidTimeStamp() throws ParsingException { - assertTrue(extractor.getTimeStamp() + "", extractor.getTimeStamp() <= 0); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "Burning Everyone's Koran"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return URL; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testGetValidTimeStamp() throws IOException, ExtractionException { - StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174"); - assertEquals(extractor.getTimeStamp() + "", "174"); - } - - @Test - @Ignore - public void testGetAgeLimit() throws ParsingException { - assertEquals(18, extractor.getAgeLimit()); - } - - @Test - public void testGetName() throws ParsingException { - assertNotNull("name is null", extractor.getName()); - assertFalse("name is empty", extractor.getName().isEmpty()); - } - - @Test - public void testGetDescription() throws ParsingException { - assertNotNull(extractor.getDescription()); - assertFalse(extractor.getDescription().getContent().isEmpty()); - } - - @Test - public void testGetUploaderName() throws ParsingException { - assertNotNull(extractor.getUploaderName()); - assertFalse(extractor.getUploaderName().isEmpty()); - } - - @Test - public void testGetLength() throws ParsingException { - assertEquals(219, extractor.getLength()); - } - - @Test - public void testGetViews() throws ParsingException { - assertTrue(extractor.getViewCount() > 0); - } - - @Test - public void testGetTextualUploadDate() throws ParsingException { - assertEquals("2010-09-09", extractor.getTextualUploadDate()); - } - - @Test - public void testGetUploadDate() throws ParsingException, ParseException { - final Calendar instance = Calendar.getInstance(); - instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2010-09-09")); - assertEquals(instance, requireNonNull(extractor.getUploadDate()).date()); - } - - @Test - public void testGetThumbnailUrl() throws ParsingException { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Test - public void testGetUploaderAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testGetAudioStreams() throws IOException, ExtractionException { - // audio streams are not always necessary - assertFalse(extractor.getAudioStreams().isEmpty()); - } - - @Test - public void testGetVideoStreams() throws IOException, ExtractionException { - List streams = new ArrayList<>(); - streams.addAll(extractor.getVideoStreams()); - streams.addAll(extractor.getVideoOnlyStreams()); - assertTrue(streams.size() > 0); - } - - @Test - public void testGetSubtitlesListDefault() throws IOException, ExtractionException { - // Video (/view?v=T4XJQO3qol8) set in the setUp() method has at least auto-generated (English) captions - assertFalse(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetSubtitlesList() throws IOException, ExtractionException { - // Video (/view?v=T4XJQO3qol8) set in the setUp() method has at least auto-generated (English) captions - assertFalse(extractor.getSubtitles(MediaFormat.TTML).isEmpty()); + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "Amazing Atheist"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCjNxszyFPasDdRoD9J6X-sw"; } + @Override public List expectedDescriptionContains() { + return Arrays.asList("http://www.huffingtonpost.com/2010/09/09/obama-gma-interview-quran_n_710282.html", + "freedom"); } + @Override public long expectedLength() { return 219; } + @Override public long expectedViewCountAtLeast() { return 285000; } + @Nullable @Override public String expectedUploadDate() { return "2010-09-09 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2010-09-09"; } + @Override public long expectedLikeCountAtLeast() { return 13300; } + @Override public long expectedDislikeCountAtLeast() { return 2600; } } 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 0d36fd9a8..49369831b 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 @@ -1,35 +1,22 @@ package org.schabi.newpipe.extractor.services.youtube.stream; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.schabi.newpipe.DownloaderTestImpl; -import org.schabi.newpipe.extractor.ExtractorAsserts; -import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.stream.Frameset; +import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.stream.StreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamType; -import org.schabi.newpipe.extractor.stream.VideoStream; -import org.schabi.newpipe.extractor.utils.Utils; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; +import java.util.Arrays; import java.util.List; -import static java.util.Objects.requireNonNull; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import javax.annotation.Nullable; + import static org.junit.Assert.fail; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.YouTube; /* @@ -51,11 +38,8 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube; * You should have received a copy of the GNU General Public License * along with NewPipe. If not, see . */ - -/** - * Test for {@link StreamExtractor} - */ public class YoutubeStreamExtractorDefaultTest { + static final String BASE_URL = "https://www.youtube.com/watch?v="; public static class NotAvailable { @BeforeClass @@ -66,266 +50,163 @@ public class YoutubeStreamExtractorDefaultTest { @Test(expected = ContentNotAvailableException.class) public void nonExistentFetch() throws Exception { final StreamExtractor extractor = - YouTube.getStreamExtractor("https://www.youtube.com/watch?v=don-t-exist"); + YouTube.getStreamExtractor(BASE_URL + "don-t-exist"); extractor.fetchPage(); } @Test(expected = ParsingException.class) public void invalidId() throws Exception { final StreamExtractor extractor = - YouTube.getStreamExtractor("https://www.youtube.com/watch?v=INVALID_ID_INVALID_ID"); + YouTube.getStreamExtractor(BASE_URL + "INVALID_ID_INVALID_ID"); extractor.fetchPage(); } } - /** - * Test for {@link StreamExtractor} - */ - public static class AdeleHello { - private static YoutubeStreamExtractor extractor; + public static class AdeleHello extends DefaultStreamExtractorTest { + private static final String ID = "YQHsXMglC9A"; + private static final String URL = BASE_URL + ID; + private static StreamExtractor extractor; @BeforeClass public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=YQHsXMglC9A"); + extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } @Test - public void testGetInvalidTimeStamp() throws ParsingException { - assertTrue(extractor.getTimeStamp() + "", - extractor.getTimeStamp() <= 0); - } - - @Test - public void testGetValidTimeStamp() throws ExtractionException { - StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174"); - assertEquals(extractor.getTimeStamp() + "", "174"); - } - - @Test - public void testGetTitle() throws ParsingException { - assertFalse(extractor.getName().isEmpty()); - } - - @Test - public void testGetDescription() throws ParsingException { - assertNotNull(extractor.getDescription()); - assertFalse(extractor.getDescription().getContent().isEmpty()); - } - - @Test - public void testGetFullLinksInDescription() throws ParsingException { - assertTrue(extractor.getDescription().getContent().contains("http://adele.com")); - } - - @Test - public void testGetUploaderName() throws ParsingException { - assertNotNull(extractor.getUploaderName()); - assertFalse(extractor.getUploaderName().isEmpty()); - } - - - @Test - public void testGetLength() throws ParsingException { - assertEquals(367, extractor.getLength()); - } - - @Test - public void testGetViewCount() throws ParsingException { - Long count = extractor.getViewCount(); - assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784); - } - - @Test - public void testGetTextualUploadDate() throws ParsingException { - Assert.assertEquals("2015-10-22", extractor.getTextualUploadDate()); - } - - @Test - public void testGetUploadDate() throws ParsingException, ParseException { - final Calendar instance = Calendar.getInstance(); - instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2015-10-22")); - assertEquals(instance, requireNonNull(extractor.getUploadDate()).date()); - } - - @Test - public void testGetUploaderUrl() throws ParsingException { - String url = extractor.getUploaderUrl(); + @Override + public void testUploaderUrl() throws ParsingException { + String url = extractor().getUploaderUrl(); if (!url.equals("https://www.youtube.com/channel/UCsRM0YB_dabtEPGPTKo-gcw") && !url.equals("https://www.youtube.com/channel/UComP_epzeKzvBX156r6pm1Q")) { fail("Uploader url is neither the music channel one nor the Vevo one"); } } - @Test - public void testGetThumbnailUrl() throws ParsingException { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "Adele - Hello"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return URL; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testGetUploaderAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testGetAudioStreams() throws ExtractionException { - assertFalse(extractor.getAudioStreams().isEmpty()); - } - - @Test - public void testGetVideoStreams() throws ExtractionException { - for (VideoStream s : extractor.getVideoStreams()) { - assertIsSecureUrl(s.url); - assertTrue(s.resolution.length() > 0); - assertTrue(Integer.toString(s.getFormatId()), - 0 <= s.getFormatId() && s.getFormatId() <= 0x100); - } - } - - @Test - public void testStreamType() throws ParsingException { - assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM); - } - - @Test - public void testGetDashMpd() throws ParsingException { - // we dont expect this particular video to have a DASH file. For this purpouse we use a different test class. - assertTrue(extractor.getDashMpdUrl(), - extractor.getDashMpdUrl() != null && extractor.getDashMpdUrl().isEmpty()); - } - - @Test - public void testGetRelatedVideos() throws ExtractionException { - StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); - Utils.printErrors(relatedVideos.getErrors()); - assertFalse(relatedVideos.getItems().isEmpty()); - assertTrue(relatedVideos.getErrors().isEmpty()); - } - - @Test - public void testGetSubtitlesListDefault() { - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetSubtitlesList() { - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null - assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty()); - } - - @Test - public void testGetLikeCount() throws ParsingException { - long likeCount = extractor.getLikeCount(); - assertTrue("" + likeCount, likeCount >= 15000000); - } - - @Test - public void testGetDislikeCount() throws ParsingException { - long dislikeCount = extractor.getDislikeCount(); - assertTrue("" + dislikeCount, dislikeCount >= 818000); - } + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "Adele"; } + @Override public String expectedUploaderUrl() { return null; } // overridden above + @Override public List expectedDescriptionContains() { return Arrays.asList("http://adele.com", "https://www.facebook.com/Adele"); } + @Override public long expectedLength() { return 367; } + @Override public long expectedViewCountAtLeast() { return 1220025784; } + @Nullable @Override public String expectedUploadDate() { return "2015-10-22 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2015-10-22"; } + @Override public long expectedLikeCountAtLeast() { return 15289000; } + @Override public long expectedDislikeCountAtLeast() { return 826000; } + @Override public boolean expectedHasSubtitles() { return false; } } - public static class DescriptionTestPewdiepie { - private static YoutubeStreamExtractor extractor; + public static class DescriptionTestPewdiepie extends DefaultStreamExtractorTest { + private static final String ID = "fBc4Q_htqPg"; + private static final int TIMESTAMP = 17; + private static final String URL = BASE_URL + ID + "&t=" + TIMESTAMP; + private static StreamExtractor extractor; @BeforeClass public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=fBc4Q_htqPg"); + extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testGetDescription() throws ParsingException { - assertNotNull(extractor.getDescription()); - assertFalse(extractor.getDescription().getContent().isEmpty()); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "Dr. Phil DESTROYS spoiled brat!!!! . -- Dr Phil #7"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return BASE_URL + ID; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testGetFullLinksInDescription() throws ParsingException { - assertTrue(extractor.getDescription().getContent().contains("https://www.reddit.com/r/PewdiepieSubmissions/")); - assertTrue(extractor.getDescription().getContent().contains("https://www.youtube.com/channel/UC3e8EMTOn4g6ZSKggHTnNng")); - assertTrue(extractor.getDescription().getContent().contains("https://usa.clutchchairz.com/product/pewdiepie-edition-throttle-series/")); + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "PewDiePie"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UC-lHJZR3Gqxm24_Vd_AJ5Yw"; } + @Override public List expectedDescriptionContains() { + return Arrays.asList("https://www.reddit.com/r/PewdiepieSubmissions/", + "https://www.youtube.com/channel/UC3e8EMTOn4g6ZSKggHTnNng", + "https://usa.clutchchairz.com/product/pewdiepie-edition-throttle-series/"); } + @Override public long expectedLength() { return 1165; } + @Override public long expectedTimestamp() { return TIMESTAMP; } + @Override public long expectedViewCountAtLeast() { return 26682500; } + @Nullable @Override public String expectedUploadDate() { return "2018-09-12 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2018-09-12"; } + @Override public long expectedLikeCountAtLeast() { return 1166000; } + @Override public long expectedDislikeCountAtLeast() { return 16900; } } - public static class DescriptionTestUnboxing { - private static YoutubeStreamExtractor extractor; + public static class DescriptionTestUnboxing extends DefaultStreamExtractorTest { + private static final String ID = "cV5TjZCJkuA"; + private static final String URL = BASE_URL + ID; + private static StreamExtractor extractor; @BeforeClass public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=cV5TjZCJkuA"); + extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testGetDescription() throws ParsingException { - assertNotNull(extractor.getDescription()); - assertFalse(extractor.getDescription().getContent().isEmpty()); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "This Smartphone Changes Everything..."; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return URL; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testGetFullLinksInDescription() throws ParsingException { - final String description = extractor.getDescription().getContent(); - assertTrue(description.contains("https://www.youtube.com/watch?v=X7FLCHVXpsA&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34")); - assertTrue(description.contains("https://www.youtube.com/watch?v=Lqv6G0pDNnw&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34")); - assertTrue(description.contains("https://www.youtube.com/watch?v=XxaRBPyrnBU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34")); - assertTrue(description.contains("https://www.youtube.com/watch?v=U-9tUEOFKNU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34")); + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "Unbox Therapy"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCsTcErHg8oDvUnTzoqsYeNw"; } + @Override public List expectedDescriptionContains() { + return Arrays.asList("https://www.youtube.com/watch?v=X7FLCHVXpsA&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34", + "https://www.youtube.com/watch?v=Lqv6G0pDNnw&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34", + "https://www.youtube.com/watch?v=XxaRBPyrnBU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34", + "https://www.youtube.com/watch?v=U-9tUEOFKNU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"); } + @Override public long expectedLength() { return 434; } + @Override public long expectedViewCountAtLeast() { return 21229200; } + @Nullable @Override public String expectedUploadDate() { return "2018-06-19 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2018-06-19"; } + @Override public long expectedLikeCountAtLeast() { return 340100; } + @Override public long expectedDislikeCountAtLeast() { return 18700; } } - public static class RatingsDisabledTest { - private static YoutubeStreamExtractor extractor; + public static class RatingsDisabledTest extends DefaultStreamExtractorTest { + private static final String ID = "HRKu0cvrr_o"; + private static final int TIMESTAMP = 17; + private static final String URL = BASE_URL + ID + "&t=" + TIMESTAMP; + private static StreamExtractor extractor; @BeforeClass public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=HRKu0cvrr_o"); + extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testGetLikeCount() throws ParsingException { - assertEquals(-1, extractor.getLikeCount()); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "AlphaOmegaSin Fanboy Logic: Likes/Dislikes Disabled = Point Invalid Lol wtf?"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return BASE_URL + ID; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testGetDislikeCount() throws ParsingException { - assertEquals(-1, extractor.getDislikeCount()); - } - - } - - public static class FramesTest { - private static YoutubeStreamExtractor extractor; - - @BeforeClass - public static void setUp() throws Exception { - NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=HoK9shIJ2xQ"); - extractor.fetchPage(); - } - - @Test - public void testGetFrames() throws ExtractionException { - final List frames = extractor.getFrames(); - assertNotNull(frames); - assertFalse(frames.isEmpty()); - for (final Frameset f : frames) { - for (final String url : f.getUrls()) { - ExtractorAsserts.assertIsValidUrl(url); - ExtractorAsserts.assertIsSecureUrl(url); - } - } - } + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "YouTuber PrinceOfFALLEN"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCQT2yul0lr6Ie9qNQNmw-sg"; } + @Override public List expectedDescriptionContains() { return Arrays.asList("dislikes", "Alpha", "wrong"); } + @Override public long expectedLength() { return 84; } + @Override public long expectedTimestamp() { return TIMESTAMP; } + @Override public long expectedViewCountAtLeast() { return 190; } + @Nullable @Override public String expectedUploadDate() { return "2019-01-02 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2019-01-02"; } + @Override public long expectedLikeCountAtLeast() { return -1; } + @Override public long expectedDislikeCountAtLeast() { return -1; } } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java index 0e17fe8d8..6a675487a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java @@ -1,139 +1,54 @@ package org.schabi.newpipe.extractor.services.youtube.stream; import org.junit.BeforeClass; -import org.junit.Test; import org.schabi.newpipe.DownloaderTestImpl; -import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; +import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamType; -import org.schabi.newpipe.extractor.stream.VideoStream; -import org.schabi.newpipe.extractor.utils.Utils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Nullable; + import static org.schabi.newpipe.extractor.ServiceList.YouTube; -public class YoutubeStreamExtractorLivestreamTest { - private static YoutubeStreamExtractor extractor; +public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractorTest { + private static final String ID = "5qap5aO4i9A"; + private static final int TIMESTAMP = 1737; + private static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID + "&t=" + TIMESTAMP; + private static StreamExtractor extractor; @BeforeClass public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=5qap5aO4i9A"); + extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testGetInvalidTimeStamp() throws ParsingException { - assertTrue(extractor.getTimeStamp() + "", - extractor.getTimeStamp() <= 0); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "lofi hip hop radio - beats to relax/study to"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return YoutubeStreamExtractorDefaultTest.BASE_URL + ID; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testGetTitle() throws ParsingException { - assertFalse(extractor.getName().isEmpty()); - } - - @Test - public void testGetDescription() throws ParsingException { - assertNotNull(extractor.getDescription()); - assertFalse(extractor.getDescription().getContent().isEmpty()); - } - - @Test - public void testGetFullLinksInDescription() throws ParsingException { - assertTrue(extractor.getDescription().getContent().contains("https://bit.ly/chilledcow-playlists")); - } - - @Test - public void testGetUploaderName() throws ParsingException { - assertNotNull(extractor.getUploaderName()); - assertFalse(extractor.getUploaderName().isEmpty()); - } - - - @Test - public void testGetLength() throws ParsingException { - assertEquals(0, extractor.getLength()); - } - - @Test - public void testGetViewCount() throws ParsingException { - long count = extractor.getViewCount(); - assertTrue(Long.toString(count), count > -1); - } - - @Test - public void testGetUploadDate() throws ParsingException { - assertNull(extractor.getUploadDate()); - assertNull(extractor.getTextualUploadDate()); - } - - @Test - public void testGetUploaderUrl() throws ParsingException { - assertEquals("https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow", extractor.getUploaderUrl()); - } - - @Test - public void testGetThumbnailUrl() throws ParsingException { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Test - public void testGetUploaderAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testGetAudioStreams() throws ExtractionException { - assertFalse(extractor.getAudioStreams().isEmpty()); - } - - @Test - public void testGetVideoStreams() throws ExtractionException { - for (VideoStream s : extractor.getVideoStreams()) { - assertIsSecureUrl(s.url); - assertTrue(s.resolution.length() > 0); - assertTrue(Integer.toString(s.getFormatId()), - 0 <= s.getFormatId() && s.getFormatId() <= 0x100); - } - } - - @Test - public void testStreamType() throws ParsingException { - assertSame(extractor.getStreamType(), StreamType.LIVE_STREAM); - } - - @Test - public void testGetDashMpd() throws ParsingException { - assertTrue(extractor.getDashMpdUrl().startsWith("https://manifest.googlevideo.com/api/manifest/dash/")); - } - - @Test - public void testGetRelatedVideos() throws ExtractionException { - StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); - Utils.printErrors(relatedVideos.getErrors()); - assertFalse(relatedVideos.getItems().isEmpty()); - assertTrue(relatedVideos.getErrors().isEmpty()); - } - - @Test - public void testGetSubtitlesListDefault() { - assertTrue(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetSubtitlesList() { - assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty()); + @Override public StreamType expectedStreamType() { return StreamType.LIVE_STREAM; } + @Override public String expectedUploaderName() { return "ChilledCow"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow"; } + @Override public List expectedDescriptionContains() { + return Arrays.asList("https://bit.ly/chilledcow-playlists", + "https://bit.ly/chilledcow-submissions"); } + @Override public long expectedLength() { return 0; } + @Override public long expectedTimestamp() { return TIMESTAMP; } + @Override public long expectedViewCountAtLeast() { return 0; } + @Nullable @Override public String expectedUploadDate() { return null; } + @Nullable @Override public String expectedTextualUploadDate() { return null; } + @Override public long expectedLikeCountAtLeast() { return 825000; } + @Override public long expectedDislikeCountAtLeast() { return 15600; } + @Override public boolean expectedHasSubtitles() { return false; } + @Override public boolean expectedHasFrames() { return false; } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java index 49a851f4f..22b537ddd 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java @@ -1,161 +1,50 @@ package org.schabi.newpipe.extractor.services.youtube.stream; -import org.junit.Assert; import org.junit.BeforeClass; -import org.junit.Test; import org.schabi.newpipe.DownloaderTestImpl; -import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.stream.AudioStream; -import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; +import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamType; -import org.schabi.newpipe.extractor.stream.VideoStream; -import org.schabi.newpipe.extractor.utils.Utils; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; +import java.util.Arrays; import java.util.List; -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import javax.annotation.Nullable; + import static org.schabi.newpipe.extractor.ServiceList.YouTube; -public class YoutubeStreamExtractorUnlistedTest { - private static YoutubeStreamExtractor extractor; +public class YoutubeStreamExtractorUnlistedTest extends DefaultStreamExtractorTest { + static final String ID = "udsB8KnIJTg"; + static final String URL = YoutubeStreamExtractorDefaultTest.BASE_URL + ID; + private static StreamExtractor extractor; @BeforeClass public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); - extractor = (YoutubeStreamExtractor) YouTube - .getStreamExtractor("https://www.youtube.com/watch?v=udsB8KnIJTg"); + extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } - @Test - public void testGetInvalidTimeStamp() throws ParsingException { - assertTrue(extractor.getTimeStamp() + "", - extractor.getTimeStamp() <= 0); - } + @Override public StreamExtractor extractor() { return extractor; } + @Override public StreamingService expectedService() { return YouTube; } + @Override public String expectedName() { return "Praise the Casual: Ein Neuling trifft Dark Souls - Folge 5"; } + @Override public String expectedId() { return ID; } + @Override public String expectedUrlContains() { return URL; } + @Override public String expectedOriginalUrlContains() { return URL; } - @Test - public void testGetTitle() throws ParsingException { - assertFalse(extractor.getName().isEmpty()); - } - - @Test - public void testGetDescription() throws ParsingException { - assertNotNull(extractor.getDescription()); - assertFalse(extractor.getDescription().getContent().isEmpty()); - } - - @Test - public void testGetFullLinksInDescription() throws ParsingException { - assertTrue(extractor.getDescription().getContent().contains("https://www.youtube.com/user/Roccowschiptune")); - } - - @Test - public void testGetUploaderName() throws ParsingException { - assertNotNull(extractor.getUploaderName()); - assertFalse(extractor.getUploaderName().isEmpty()); - } - - - @Test - public void testGetLength() throws ParsingException { - assertEquals(2488, extractor.getLength()); - } - - @Test - public void testGetViewCount() throws ParsingException { - long count = extractor.getViewCount(); - assertTrue(Long.toString(count), count >= /* specific to that video */ 1225); - } - - @Test - public void testGetTextualUploadDate() throws ParsingException { - Assert.assertEquals("2017-09-22", extractor.getTextualUploadDate()); - } - - @Test - public void testGetUploadDate() throws ParsingException, ParseException { - final Calendar instance = Calendar.getInstance(); - instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2017-09-22")); - assertNotNull(extractor.getUploadDate()); - assertEquals(instance, extractor.getUploadDate().date()); - } - - @Test - public void testGetUploaderUrl() throws ParsingException { - assertEquals("https://www.youtube.com/channel/UCPysfiuOv4VKBeXFFPhKXyw", extractor.getUploaderUrl()); - } - - @Test - public void testGetThumbnailUrl() throws ParsingException { - assertIsSecureUrl(extractor.getThumbnailUrl()); - } - - @Test - public void testGetUploaderAvatarUrl() throws ParsingException { - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); - } - - @Test - public void testGetAudioStreams() throws ExtractionException { - List audioStreams = extractor.getAudioStreams(); - assertFalse(audioStreams.isEmpty()); - for (AudioStream s : audioStreams) { - assertIsSecureUrl(s.url); - assertTrue(Integer.toString(s.getFormatId()), - 0x100 <= s.getFormatId() && s.getFormatId() < 0x1000); - } - } - - @Test - public void testGetVideoStreams() throws ExtractionException { - for (VideoStream s : extractor.getVideoStreams()) { - assertIsSecureUrl(s.url); - assertTrue(s.resolution.length() > 0); - assertTrue(Integer.toString(s.getFormatId()), - 0 <= s.getFormatId() && s.getFormatId() < 0x100); - } - } - - @Test - public void testStreamType() throws ParsingException { - assertSame(StreamType.VIDEO_STREAM, extractor.getStreamType()); - } - - @Test - public void testGetRelatedVideos() throws ExtractionException { - StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); - Utils.printErrors(relatedVideos.getErrors()); - assertFalse(relatedVideos.getItems().isEmpty()); - assertTrue(relatedVideos.getErrors().isEmpty()); - } - - @Test - public void testGetSubtitlesListDefault() { - assertFalse(extractor.getSubtitlesDefault().isEmpty()); - } - - @Test - public void testGetSubtitlesList() { - assertFalse(extractor.getSubtitles(MediaFormat.TTML).isEmpty()); - } - - @Test - public void testGetLikeCount() throws ParsingException { - long likeCount = extractor.getLikeCount(); - assertTrue("" + likeCount, likeCount >= 96); - } - - @Test - public void testGetDislikeCount() throws ParsingException { - long dislikeCount = extractor.getDislikeCount(); - assertTrue("" + dislikeCount, dislikeCount >= 0); + @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } + @Override public String expectedUploaderName() { return "Hooked"; } + @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCPysfiuOv4VKBeXFFPhKXyw"; } + @Override public List expectedDescriptionContains() { + return Arrays.asList("https://www.youtube.com/user/Roccowschiptune", + "https://www.facebook.com/HookedMagazinDE"); } + @Override public long expectedLength() { return 2488; } + @Override public long expectedViewCountAtLeast() { return 1500; } + @Nullable @Override public String expectedUploadDate() { return "2017-09-22 00:00:00.000"; } + @Nullable @Override public String expectedTextualUploadDate() { return "2017-09-22"; } + @Override public long expectedLikeCountAtLeast() { return 110; } + @Override public long expectedDislikeCountAtLeast() { return 0; } }