2017-07-10 00:43:04 +02:00
|
|
|
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;
|
2017-07-10 00:43:04 +02:00
|
|
|
import java.io.IOException;
|
2017-08-06 22:20:15 +02:00
|
|
|
import java.util.List;
|
2017-07-10 00:43:04 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-07 18:12:51 +02:00
|
|
|
* Base class to extractors that have a list (e.g. playlists, users).
|
2017-07-10 00:43:04 +02:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
2018-01-20 15:35:00 +01:00
|
|
|
public ListExtractor(StreamingService service, String url, String nextStreamsUrl) throws ExtractionException {
|
2017-08-06 22:20:15 +02:00
|
|
|
super(service, url);
|
|
|
|
setNextStreamsUrl(nextStreamsUrl);
|
2017-07-10 00:43:04 +02:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2017-07-10 00:43:04 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2018-01-20 15:35:00 +01:00
|
|
|
public final List<InfoItem> nextItemsList;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Next url to fetch more items
|
|
|
|
*/
|
|
|
|
public final String nextItemsUrl;
|
|
|
|
|
2017-08-12 22:19:56 +02:00
|
|
|
/**
|
|
|
|
* Errors that happened during the extraction
|
|
|
|
*/
|
|
|
|
public final List<Throwable> errors;
|
|
|
|
|
2018-01-20 15:35:00 +01:00
|
|
|
public NextItemsResult(InfoItemCollector collector, String nextItemsUrl) {
|
2017-08-12 22:19:56 +02:00
|
|
|
this(collector.getItemList(), nextItemsUrl, collector.getErrors());
|
|
|
|
}
|
|
|
|
|
2018-01-20 15:35:00 +01:00
|
|
|
public NextItemsResult(List<InfoItem> nextItemsList, String nextItemsUrl, List<Throwable> errors) {
|
2017-08-06 22:20:15 +02:00
|
|
|
this.nextItemsList = nextItemsList;
|
|
|
|
this.nextItemsUrl = nextItemsUrl;
|
2017-08-12 22:19:56 +02:00
|
|
|
this.errors = errors;
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasMoreStreams() {
|
|
|
|
return nextItemsUrl != null && !nextItemsUrl.isEmpty();
|
|
|
|
}
|
2017-11-11 12:17:14 +01:00
|
|
|
|
2018-01-20 15:35:00 +01:00
|
|
|
public List<InfoItem> getNextItemsList() {
|
2017-11-11 12:17:14 +01:00
|
|
|
return nextItemsList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getNextItemsUrl() {
|
|
|
|
return nextItemsUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Throwable> getErrors() {
|
|
|
|
return errors;
|
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
2017-07-10 00:43:04 +02:00
|
|
|
}
|