Generify related streams calls and rename method

This commit is contained in:
Fynn Godau 2021-03-31 20:21:49 +02:00
parent 705f6c6e33
commit 14f6f1b7c3
16 changed files with 34 additions and 30 deletions

View File

@ -245,7 +245,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
} }
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() { public StreamInfoItemsCollector getRelatedItems() {
return null; return null;
} }

View File

@ -240,7 +240,7 @@ public class MediaCCCLiveStreamExtractor extends StreamExtractor {
@Nullable @Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() { public StreamInfoItemsCollector getRelatedItems() {
return null; return null;
} }

View File

@ -219,7 +219,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
@Nullable @Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() { public StreamInfoItemsCollector getRelatedItems() {
return null; return null;
} }

View File

@ -263,7 +263,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
@Nullable @Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException {
final List<String> tags = getTags(); final List<String> tags = getTags();
final String apiUrl; final String apiUrl;
if (tags.isEmpty()) { if (tags.isEmpty()) {
@ -271,7 +271,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
+ "@" + JsonUtils.getString(json, "account.host") + + "@" + JsonUtils.getString(json, "account.host") +
"/videos?start=0&count=8"; "/videos?start=0&count=8";
} else { } else {
apiUrl = getRelatedStreamsUrl(tags); apiUrl = getRelatedItemsUrl(tags);
} }
if (Utils.isBlank(apiUrl)) { if (Utils.isBlank(apiUrl)) {
@ -311,7 +311,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
return Collections.emptyList(); return Collections.emptyList();
} }
private String getRelatedStreamsUrl(final List<String> tags) throws UnsupportedEncodingException { private String getRelatedItemsUrl(final List<String> tags) throws UnsupportedEncodingException {
final String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT; final String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT;
final StringBuilder params = new StringBuilder(); final StringBuilder params = new StringBuilder();
params.append("start=0&count=8&sort=-createdAt"); params.append("start=0&count=8&sort=-createdAt");

View File

@ -353,7 +353,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
@Nullable @Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException { public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException {
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
final String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId()) final String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId())

View File

@ -643,7 +643,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
@Nullable @Nullable
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException { public StreamInfoItemsCollector getRelatedItems() throws ExtractionException {
assertPageFetched(); assertPageFetched();
if (getAgeLimit() != NO_AGE_LIMIT) { if (getAgeLimit() != NO_AGE_LIMIT) {

View File

@ -20,6 +20,9 @@ package org.schabi.newpipe.extractor.stream;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
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.Extractor;
import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.MetaInfo; import org.schabi.newpipe.extractor.MetaInfo;
@ -331,7 +334,8 @@ public abstract class StreamExtractor extends Extractor {
* @throws ExtractionException * @throws ExtractionException
*/ */
@Nullable @Nullable
public abstract StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException; public abstract InfoItemsCollector<? extends InfoItem, ? extends InfoItemExtractor>
getRelatedItems() throws IOException, ExtractionException;
/** /**
* Should return a list of Frameset object that contains preview of stream frames * Should return a list of Frameset object that contains preview of stream frames

View File

@ -334,7 +334,7 @@ public class StreamInfo extends Info {
streamInfo.addError(e); streamInfo.addError(e);
} }
streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor)); streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor));
return streamInfo; return streamInfo;
} }
@ -370,7 +370,7 @@ public class StreamInfo extends Info {
private String hlsUrl = ""; private String hlsUrl = "";
private List<InfoItem> relatedStreams = new ArrayList<>(); private List<InfoItem> relatedItems = new ArrayList<>();
private long startPosition = 0; private long startPosition = 0;
private List<SubtitlesStream> subtitles = new ArrayList<>(); private List<SubtitlesStream> subtitles = new ArrayList<>();
@ -602,12 +602,12 @@ public class StreamInfo extends Info {
this.hlsUrl = hlsUrl; this.hlsUrl = hlsUrl;
} }
public List<InfoItem> getRelatedStreams() { public List<InfoItem> getRelatedItems() {
return relatedStreams; return relatedItems;
} }
public void setRelatedStreams(List<InfoItem> relatedStreams) { public void setRelatedItems(List<InfoItem> relatedItems) {
this.relatedStreams = relatedStreams; this.relatedItems = relatedItems;
} }
public long getStartPosition() { public long getStartPosition() {

View File

@ -27,9 +27,9 @@ public class ExtractorHelper {
} }
public static List<InfoItem> getRelatedVideosOrLogError(StreamInfo info, StreamExtractor extractor) { public static List<InfoItem> getRelatedItemsOrLogError(StreamInfo info, StreamExtractor extractor) {
try { try {
InfoItemsCollector<? extends InfoItem, ?> collector = extractor.getRelatedStreams(); InfoItemsCollector<? extends InfoItem, ?> collector = extractor.getRelatedItems();
if (collector == null) return Collections.emptyList(); if (collector == null) return Collections.emptyList();
info.addAllErrors(collector.getErrors()); info.addAllErrors(collector.getErrors());

View File

@ -17,7 +17,7 @@ public interface BaseStreamExtractorTest extends BaseExtractorTest {
void testTextualUploadDate() throws Exception; void testTextualUploadDate() throws Exception;
void testLikeCount() throws Exception; void testLikeCount() throws Exception;
void testDislikeCount() throws Exception; void testDislikeCount() throws Exception;
void testRelatedStreams() throws Exception; void testRelatedItems() throws Exception;
void testAgeLimit() throws Exception; void testAgeLimit() throws Exception;
void testErrorMessage() throws Exception; void testErrorMessage() throws Exception;
void testAudioStreams() throws Exception; void testAudioStreams() throws Exception;

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.extractor.services; package org.schabi.newpipe.extractor.services;
import org.junit.Test; import org.junit.Test;
import org.schabi.newpipe.extractor.InfoItemsCollector;
import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.MetaInfo; import org.schabi.newpipe.extractor.MetaInfo;
import org.schabi.newpipe.extractor.localization.DateWrapper; 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.Description;
import org.schabi.newpipe.extractor.stream.Frameset; import org.schabi.newpipe.extractor.stream.Frameset;
import org.schabi.newpipe.extractor.stream.StreamExtractor; 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.StreamType;
import org.schabi.newpipe.extractor.stream.SubtitlesStream; import org.schabi.newpipe.extractor.stream.SubtitlesStream;
import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.stream.VideoStream;
@ -57,7 +57,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
@Nullable public abstract String expectedTextualUploadDate(); @Nullable public abstract String expectedTextualUploadDate();
public abstract long expectedLikeCountAtLeast(); // return -1 if ratings are disabled public abstract long expectedLikeCountAtLeast(); // return -1 if ratings are disabled
public abstract long expectedDislikeCountAtLeast(); // 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 boolean expectedHasRelatedItems() { return true; } // default: there are related videos
public int expectedAgeLimit() { return StreamExtractor.NO_AGE_LIMIT; } // default: no limit public int expectedAgeLimit() { return StreamExtractor.NO_AGE_LIMIT; } // default: no limit
@Nullable public String expectedErrorMessage() { return null; } // default: no error message @Nullable public String expectedErrorMessage() { return null; } // default: no error message
public boolean expectedHasVideoStreams() { return true; } // default: there are video streams public boolean expectedHasVideoStreams() { return true; } // default: there are video streams
@ -223,10 +223,10 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
@Test @Test
@Override @Override
public void testRelatedStreams() throws Exception { public void testRelatedItems() throws Exception {
final StreamInfoItemsCollector relatedStreams = extractor().getRelatedStreams(); final InfoItemsCollector<?, ?> relatedStreams = extractor().getRelatedItems();
if (expectedHasRelatedStreams()) { if (expectedHasRelatedItems()) {
assertNotNull(relatedStreams); assertNotNull(relatedStreams);
defaultTestListOfItems(extractor().getService(), relatedStreams.getItems(), defaultTestListOfItems(extractor().getService(), relatedStreams.getItems(),
relatedStreams.getErrors()); relatedStreams.getErrors());

View File

@ -50,7 +50,7 @@ public class BandcampRadioStreamExtractorTest extends DefaultStreamExtractorTest
@Override public boolean expectedHasVideoStreams() { return false; } @Override public boolean expectedHasVideoStreams() { return false; }
@Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasSubtitles() { return false; }
@Override public boolean expectedHasFrames() { 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 StreamType expectedStreamType() { return StreamType.AUDIO_STREAM; }
@Override public StreamingService expectedService() { return Bandcamp; } @Override public StreamingService expectedService() { return Bandcamp; }
@Override public String expectedUploaderName() { return "Andrew Jervis"; } @Override public String expectedUploaderName() { return "Andrew Jervis"; }

View File

@ -125,7 +125,7 @@ public class BandcampStreamExtractorTest extends DefaultStreamExtractorTest {
} }
@Override @Override
public boolean expectedHasRelatedStreams() { public boolean expectedHasRelatedItems() {
return false; return false;
} }

View File

@ -54,7 +54,7 @@ public class MediaCCCStreamExtractorTest {
@Nullable @Override public String expectedTextualUploadDate() { return "2018-05-11T02:00:00.000+02:00"; } @Nullable @Override public String expectedTextualUploadDate() { return "2018-05-11T02:00:00.000+02:00"; }
@Override public long expectedLikeCountAtLeast() { return -1; } @Override public long expectedLikeCountAtLeast() { return -1; }
@Override public long expectedDislikeCountAtLeast() { 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 expectedHasSubtitles() { return false; }
@Override public boolean expectedHasFrames() { return false; } @Override public boolean expectedHasFrames() { return false; }
@Override public List<String> expectedTags() { return Arrays.asList("gpn18", "105"); } @Override public List<String> 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"; } @Nullable @Override public String expectedTextualUploadDate() { return "2020-01-11T01:00:00.000+01:00"; }
@Override public long expectedLikeCountAtLeast() { return -1; } @Override public long expectedLikeCountAtLeast() { return -1; }
@Override public long expectedDislikeCountAtLeast() { 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 expectedHasSubtitles() { return false; }
@Override public boolean expectedHasFrames() { return false; } @Override public boolean expectedHasFrames() { return false; }
@Override public List<String> expectedTags() { return Arrays.asList("36c3", "10565", "2019", "Security", "Main"); } @Override public List<String> expectedTags() { return Arrays.asList("36c3", "10565", "2019", "Security", "Main"); }

View File

@ -70,7 +70,7 @@ public class SoundcloudStreamExtractorTest {
@Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasSubtitles() { return false; }
@Override public boolean expectedHasFrames() { return false; } @Override public boolean expectedHasFrames() { return false; }
@Override public int expectedStreamSegmentsCount() { return 0; } @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 expectedLicence() { return "all-rights-reserved"; }
@Override public String expectedCategory() { return "Pop"; } @Override public String expectedCategory() { return "Pop"; }
} }
@ -115,7 +115,7 @@ public class SoundcloudStreamExtractorTest {
@Override public long expectedDislikeCountAtLeast() { return -1; } @Override public long expectedDislikeCountAtLeast() { return -1; }
@Override public boolean expectedHasAudioStreams() { return false; } @Override public boolean expectedHasAudioStreams() { return false; }
@Override public boolean expectedHasVideoStreams() { 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 expectedHasSubtitles() { return false; }
@Override public boolean expectedHasFrames() { return false; } @Override public boolean expectedHasFrames() { return false; }
@Override public int expectedStreamSegmentsCount() { return 0; } @Override public int expectedStreamSegmentsCount() { return 0; }

View File

@ -50,7 +50,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtrac
@Nullable @Override public String expectedTextualUploadDate() { return "2017-01-25"; } @Nullable @Override public String expectedTextualUploadDate() { return "2017-01-25"; }
@Override public long expectedLikeCountAtLeast() { return 149000; } @Override public long expectedLikeCountAtLeast() { return 149000; }
@Override public long expectedDislikeCountAtLeast() { return 38000; } @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; } @Override public int expectedAgeLimit() { return 18; }
@Nullable @Override public String expectedErrorMessage() { return "Sign in to confirm your age"; } @Nullable @Override public String expectedErrorMessage() { return "Sign in to confirm your age"; }
@Override public boolean expectedHasSubtitles() { return false; } @Override public boolean expectedHasSubtitles() { return false; }