NewPipeExtractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java

89 lines
2.5 KiB
Java
Raw Normal View History

package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
2017-11-25 02:03:30 +01:00
import javax.annotation.Nonnull;
import java.io.IOException;
2017-08-06 22:20:15 +02:00
import java.util.List;
/**
2017-08-07 18:12:51 +02:00
* Base class to extractors that have a list (e.g. playlists, users).
*/
public abstract class ListExtractor extends Extractor {
protected String nextStreamsUrl;
2017-08-06 22:20:15 +02:00
/**
* Get a new ListExtractor with the given nextStreamsUrl set.
*/
public ListExtractor(StreamingService service, String url, String nextStreamsUrl) throws ExtractionException {
2017-08-06 22:20:15 +02:00
super(service, url);
setNextStreamsUrl(nextStreamsUrl);
}
2017-11-25 02:03:30 +01:00
@Nonnull
2017-08-06 22:20:15 +02:00
public abstract StreamInfoItemCollector getStreams() throws IOException, ExtractionException;
2017-11-25 02:03:30 +01:00
2017-08-06 22:20:15 +02:00
public abstract NextItemsResult getNextStreams() throws IOException, ExtractionException;
public boolean hasMoreStreams() {
return nextStreamsUrl != null && !nextStreamsUrl.isEmpty();
}
public String getNextStreamsUrl() {
return nextStreamsUrl;
}
public void setNextStreamsUrl(String nextStreamsUrl) {
this.nextStreamsUrl = nextStreamsUrl;
}
2017-08-06 22:20:15 +02:00
/*//////////////////////////////////////////////////////////////////////////
// Inner
//////////////////////////////////////////////////////////////////////////*/
public static class NextItemsResult {
/**
* The current list of items to this result
*/
public final List<InfoItem> nextItemsList;
2017-08-06 22:20:15 +02:00
/**
* Next url to fetch more items
*/
public final String nextItemsUrl;
/**
* Errors that happened during the extraction
*/
public final List<Throwable> errors;
public NextItemsResult(InfoItemCollector collector, String nextItemsUrl) {
this(collector.getItemList(), nextItemsUrl, collector.getErrors());
}
public NextItemsResult(List<InfoItem> nextItemsList, String nextItemsUrl, List<Throwable> errors) {
2017-08-06 22:20:15 +02:00
this.nextItemsList = nextItemsList;
this.nextItemsUrl = nextItemsUrl;
this.errors = errors;
2017-08-06 22:20:15 +02:00
}
public boolean hasMoreStreams() {
return nextItemsUrl != null && !nextItemsUrl.isEmpty();
}
public List<InfoItem> getNextItemsList() {
return nextItemsList;
}
public String getNextItemsUrl() {
return nextItemsUrl;
}
public List<Throwable> getErrors() {
return errors;
}
2017-08-06 22:20:15 +02:00
}
}