Generify related streams calls and rename method
This commit is contained in:
parent
705f6c6e33
commit
14f6f1b7c3
|
@ -245,7 +245,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public StreamInfoItemsCollector getRelatedStreams() {
|
||||
public StreamInfoItemsCollector getRelatedItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -240,7 +240,7 @@ public class MediaCCCLiveStreamExtractor extends StreamExtractor {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public StreamInfoItemsCollector getRelatedStreams() {
|
||||
public StreamInfoItemsCollector getRelatedItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public StreamInfoItemsCollector getRelatedStreams() {
|
||||
public StreamInfoItemsCollector getRelatedItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> 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<String> tags) throws UnsupportedEncodingException {
|
||||
private String getRelatedItemsUrl(final List<String> tags) throws UnsupportedEncodingException {
|
||||
final String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT;
|
||||
final StringBuilder params = new StringBuilder();
|
||||
params.append("start=0&count=8&sort=-createdAt");
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -20,6 +20,9 @@ package org.schabi.newpipe.extractor.stream;
|
|||
* 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.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<? extends InfoItem, ? extends InfoItemExtractor>
|
||||
getRelatedItems() throws IOException, ExtractionException;
|
||||
|
||||
/**
|
||||
* Should return a list of Frameset object that contains preview of stream frames
|
||||
|
|
|
@ -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<InfoItem> relatedStreams = new ArrayList<>();
|
||||
private List<InfoItem> relatedItems = new ArrayList<>();
|
||||
|
||||
private long startPosition = 0;
|
||||
private List<SubtitlesStream> subtitles = new ArrayList<>();
|
||||
|
@ -602,12 +602,12 @@ public class StreamInfo extends Info {
|
|||
this.hlsUrl = hlsUrl;
|
||||
}
|
||||
|
||||
public List<InfoItem> getRelatedStreams() {
|
||||
return relatedStreams;
|
||||
public List<InfoItem> getRelatedItems() {
|
||||
return relatedItems;
|
||||
}
|
||||
|
||||
public void setRelatedStreams(List<InfoItem> relatedStreams) {
|
||||
this.relatedStreams = relatedStreams;
|
||||
public void setRelatedItems(List<InfoItem> relatedItems) {
|
||||
this.relatedItems = relatedItems;
|
||||
}
|
||||
|
||||
public long getStartPosition() {
|
||||
|
|
|
@ -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 {
|
||||
InfoItemsCollector<? extends InfoItem, ?> collector = extractor.getRelatedStreams();
|
||||
InfoItemsCollector<? extends InfoItem, ?> collector = extractor.getRelatedItems();
|
||||
if (collector == null) return Collections.emptyList();
|
||||
info.addAllErrors(collector.getErrors());
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<St
|
|||
@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 boolean expectedHasRelatedItems() { 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
|
||||
|
@ -223,10 +223,10 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
|
|||
|
||||
@Test
|
||||
@Override
|
||||
public void testRelatedStreams() throws Exception {
|
||||
final StreamInfoItemsCollector relatedStreams = extractor().getRelatedStreams();
|
||||
public void testRelatedItems() throws Exception {
|
||||
final InfoItemsCollector<?, ?> relatedStreams = extractor().getRelatedItems();
|
||||
|
||||
if (expectedHasRelatedStreams()) {
|
||||
if (expectedHasRelatedItems()) {
|
||||
assertNotNull(relatedStreams);
|
||||
defaultTestListOfItems(extractor().getService(), relatedStreams.getItems(),
|
||||
relatedStreams.getErrors());
|
||||
|
|
|
@ -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"; }
|
||||
|
|
|
@ -125,7 +125,7 @@ public class BandcampStreamExtractorTest extends DefaultStreamExtractorTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean expectedHasRelatedStreams() {
|
||||
public boolean expectedHasRelatedItems() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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"; }
|
||||
@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<String> expectedTags() { return Arrays.asList("36c3", "10565", "2019", "Security", "Main"); }
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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; }
|
||||
|
|
Loading…
Reference in New Issue