From 14f6f1b7c3d4a98ac0a74a9f6d16b05cb96c0c91 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Wed, 31 Mar 2021 20:21:49 +0200 Subject: [PATCH] Generify related streams calls and rename method --- .../bandcamp/extractors/BandcampStreamExtractor.java | 2 +- .../extractors/MediaCCCLiveStreamExtractor.java | 2 +- .../extractors/MediaCCCStreamExtractor.java | 2 +- .../peertube/extractors/PeertubeStreamExtractor.java | 6 +++--- .../extractors/SoundcloudStreamExtractor.java | 2 +- .../youtube/extractors/YoutubeStreamExtractor.java | 2 +- .../newpipe/extractor/stream/StreamExtractor.java | 6 +++++- .../schabi/newpipe/extractor/stream/StreamInfo.java | 12 ++++++------ .../newpipe/extractor/utils/ExtractorHelper.java | 4 ++-- .../extractor/services/BaseStreamExtractorTest.java | 2 +- .../services/DefaultStreamExtractorTest.java | 10 +++++----- .../bandcamp/BandcampRadioStreamExtractorTest.java | 2 +- .../bandcamp/BandcampStreamExtractorTest.java | 2 +- .../media_ccc/MediaCCCStreamExtractorTest.java | 4 ++-- .../soundcloud/SoundcloudStreamExtractorTest.java | 4 ++-- .../YoutubeStreamExtractorAgeRestrictedTest.java | 2 +- 16 files changed, 34 insertions(+), 30 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java index 7a67c07d4..f83e351a9 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java @@ -245,7 +245,7 @@ public class BandcampStreamExtractor extends StreamExtractor { } @Override - public StreamInfoItemsCollector getRelatedStreams() { + public StreamInfoItemsCollector getRelatedItems() { return null; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java index 889c3c9f4..08b6db307 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java @@ -240,7 +240,7 @@ public class MediaCCCLiveStreamExtractor extends StreamExtractor { @Nullable @Override - public StreamInfoItemsCollector getRelatedStreams() { + public StreamInfoItemsCollector getRelatedItems() { return null; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java index a9c31c72d..3251ca439 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java @@ -219,7 +219,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor { @Nullable @Override - public StreamInfoItemsCollector getRelatedStreams() { + public StreamInfoItemsCollector getRelatedItems() { return null; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java index 611838710..064a24a16 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java @@ -263,7 +263,7 @@ public class PeertubeStreamExtractor extends StreamExtractor { @Nullable @Override - public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { + public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException { final List tags = getTags(); final String apiUrl; if (tags.isEmpty()) { @@ -271,7 +271,7 @@ public class PeertubeStreamExtractor extends StreamExtractor { + "@" + JsonUtils.getString(json, "account.host") + "/videos?start=0&count=8"; } else { - apiUrl = getRelatedStreamsUrl(tags); + apiUrl = getRelatedItemsUrl(tags); } if (Utils.isBlank(apiUrl)) { @@ -311,7 +311,7 @@ public class PeertubeStreamExtractor extends StreamExtractor { return Collections.emptyList(); } - private String getRelatedStreamsUrl(final List tags) throws UnsupportedEncodingException { + private String getRelatedItemsUrl(final List tags) throws UnsupportedEncodingException { final String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT; final StringBuilder params = new StringBuilder(); params.append("start=0&count=8&sort=-createdAt"); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java index 1b53b7017..c745f1aa7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java @@ -353,7 +353,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor { @Nullable @Override - public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { + public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException { final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); final String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId()) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 0609b7689..3f6116c99 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -643,7 +643,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { @Nullable @Override - public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException { + public StreamInfoItemsCollector getRelatedItems() throws ExtractionException { assertPageFetched(); if (getAgeLimit() != NO_AGE_LIMIT) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index d430eed5f..4a7ef4002 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -20,6 +20,9 @@ package org.schabi.newpipe.extractor.stream; * along with NewPipe. If not, see . */ +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.InfoItemsCollector; +import org.schabi.newpipe.extractor.InfoItemExtractor; import org.schabi.newpipe.extractor.Extractor; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MetaInfo; @@ -331,7 +334,8 @@ public abstract class StreamExtractor extends Extractor { * @throws ExtractionException */ @Nullable - public abstract StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException; + public abstract InfoItemsCollector + getRelatedItems() throws IOException, ExtractionException; /** * Should return a list of Frameset object that contains preview of stream frames diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java index 7ff8ad9ee..88d01fa06 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -334,7 +334,7 @@ public class StreamInfo extends Info { streamInfo.addError(e); } - streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor)); + streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor)); return streamInfo; } @@ -370,7 +370,7 @@ public class StreamInfo extends Info { private String hlsUrl = ""; - private List relatedStreams = new ArrayList<>(); + private List relatedItems = new ArrayList<>(); private long startPosition = 0; private List subtitles = new ArrayList<>(); @@ -602,12 +602,12 @@ public class StreamInfo extends Info { this.hlsUrl = hlsUrl; } - public List getRelatedStreams() { - return relatedStreams; + public List getRelatedItems() { + return relatedItems; } - public void setRelatedStreams(List relatedStreams) { - this.relatedStreams = relatedStreams; + public void setRelatedItems(List relatedItems) { + this.relatedItems = relatedItems; } public long getStartPosition() { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java index c6ef73caa..076827626 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java @@ -27,9 +27,9 @@ public class ExtractorHelper { } - public static List getRelatedVideosOrLogError(StreamInfo info, StreamExtractor extractor) { + public static List getRelatedItemsOrLogError(StreamInfo info, StreamExtractor extractor) { try { - InfoItemsCollector collector = extractor.getRelatedStreams(); + InfoItemsCollector collector = extractor.getRelatedItems(); if (collector == null) return Collections.emptyList(); info.addAllErrors(collector.getErrors()); 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 index 40356cebf..f32a60907 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java @@ -17,7 +17,7 @@ public interface BaseStreamExtractorTest extends BaseExtractorTest { void testTextualUploadDate() throws Exception; void testLikeCount() throws Exception; void testDislikeCount() throws Exception; - void testRelatedStreams() throws Exception; + void testRelatedItems() throws Exception; void testAgeLimit() throws Exception; void testErrorMessage() throws Exception; void testAudioStreams() 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 index 09bc4c72d..be62955eb 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.extractor.services; import org.junit.Test; +import org.schabi.newpipe.extractor.InfoItemsCollector; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MetaInfo; import org.schabi.newpipe.extractor.localization.DateWrapper; @@ -8,7 +9,6 @@ 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; @@ -57,7 +57,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest relatedStreams = extractor().getRelatedItems(); - if (expectedHasRelatedStreams()) { + if (expectedHasRelatedItems()) { assertNotNull(relatedStreams); defaultTestListOfItems(extractor().getService(), relatedStreams.getItems(), relatedStreams.getErrors()); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampRadioStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampRadioStreamExtractorTest.java index 8773c5564..ac5938423 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampRadioStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampRadioStreamExtractorTest.java @@ -50,7 +50,7 @@ public class BandcampRadioStreamExtractorTest extends DefaultStreamExtractorTest @Override public boolean expectedHasVideoStreams() { return false; } @Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasFrames() { return false; } - @Override public boolean expectedHasRelatedStreams() { return false; } + @Override public boolean expectedHasRelatedItems() { return false; } @Override public StreamType expectedStreamType() { return StreamType.AUDIO_STREAM; } @Override public StreamingService expectedService() { return Bandcamp; } @Override public String expectedUploaderName() { return "Andrew Jervis"; } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java index a080de674..34d3459f7 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java @@ -125,7 +125,7 @@ public class BandcampStreamExtractorTest extends DefaultStreamExtractorTest { } @Override - public boolean expectedHasRelatedStreams() { + public boolean expectedHasRelatedItems() { return false; } 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 4c1adfd99..3dc19b906 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 @@ -54,7 +54,7 @@ public class MediaCCCStreamExtractorTest { @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 expectedHasRelatedStreams() { return false; } + @Override public boolean expectedHasRelatedItems() { return false; } @Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasFrames() { return false; } @Override public List expectedTags() { return Arrays.asList("gpn18", "105"); } @@ -125,7 +125,7 @@ public class MediaCCCStreamExtractorTest { @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 expectedHasRelatedStreams() { return false; } + @Override public boolean expectedHasRelatedItems() { return false; } @Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasFrames() { return false; } @Override public List expectedTags() { return Arrays.asList("36c3", "10565", "2019", "Security", "Main"); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java index beef559ed..8bc8bab8c 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java @@ -70,7 +70,7 @@ public class SoundcloudStreamExtractorTest { @Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasFrames() { return false; } @Override public int expectedStreamSegmentsCount() { return 0; } - @Override public boolean expectedHasRelatedStreams() { return false; } + @Override public boolean expectedHasRelatedItems() { return false; } @Override public String expectedLicence() { return "all-rights-reserved"; } @Override public String expectedCategory() { return "Pop"; } } @@ -115,7 +115,7 @@ public class SoundcloudStreamExtractorTest { @Override public long expectedDislikeCountAtLeast() { return -1; } @Override public boolean expectedHasAudioStreams() { return false; } @Override public boolean expectedHasVideoStreams() { return false; } - @Override public boolean expectedHasRelatedStreams() { return false; } + @Override public boolean expectedHasRelatedItems() { return false; } @Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasFrames() { return false; } @Override public int expectedStreamSegmentsCount() { return 0; } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java index b52778195..500059cb1 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 @@ -50,7 +50,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtrac @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 boolean expectedHasRelatedItems() { 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; }