2017-07-10 00:43:04 +02:00
|
|
|
package org.schabi.newpipe.extractor;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
|
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 {
|
2018-02-24 22:20:50 +01:00
|
|
|
protected String nextPageUrl;
|
2017-07-10 00:43:04 +02:00
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
/**
|
2018-02-24 22:20:50 +01:00
|
|
|
* Get a new ListExtractor with the given nextPageUrl set.
|
2017-08-06 22:20:15 +02:00
|
|
|
*/
|
2018-02-24 22:20:50 +01:00
|
|
|
public ListExtractor(StreamingService service, String url, String nextPageUrl) throws ExtractionException {
|
2017-08-06 22:20:15 +02:00
|
|
|
super(service, url);
|
2018-02-24 22:20:50 +01:00
|
|
|
setNextPageUrl(nextPageUrl);
|
2017-07-10 00:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-11-25 02:03:30 +01:00
|
|
|
@Nonnull
|
2018-02-24 22:20:50 +01:00
|
|
|
public abstract InfoItemsCollector getInfoItems() throws IOException, ExtractionException;
|
2017-11-25 02:03:30 +01:00
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public abstract InfoItemPage getInfoItemPage() throws IOException, ExtractionException;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public boolean hasNextPage() {
|
|
|
|
return nextPageUrl != null && !nextPageUrl.isEmpty();
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
2017-07-10 00:43:04 +02:00
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public String getNextPageUrl() {
|
|
|
|
return nextPageUrl;
|
2017-07-10 00:43:04 +02:00
|
|
|
}
|
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public void setNextPageUrl(String nextPageUrl) {
|
|
|
|
this.nextPageUrl = nextPageUrl;
|
2017-07-10 00:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Inner
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public static class InfoItemPage {
|
2017-08-06 22:20:15 +02:00
|
|
|
/**
|
|
|
|
* The current list of items to this result
|
|
|
|
*/
|
2018-02-24 22:20:50 +01:00
|
|
|
public final List<InfoItem> infoItemList;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Next url to fetch more items
|
|
|
|
*/
|
2018-02-24 22:20:50 +01:00
|
|
|
public final String nextPageUrl;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2017-08-12 22:19:56 +02:00
|
|
|
/**
|
|
|
|
* Errors that happened during the extraction
|
|
|
|
*/
|
|
|
|
public final List<Throwable> errors;
|
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public InfoItemPage(InfoItemsCollector collector, String nextPageUrl) {
|
|
|
|
this(collector.getItemList(), nextPageUrl, collector.getErrors());
|
2017-08-12 22:19:56 +02:00
|
|
|
}
|
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public InfoItemPage(List<InfoItem> infoItemList, String nextPageUrl, List<Throwable> errors) {
|
|
|
|
this.infoItemList = infoItemList;
|
|
|
|
this.nextPageUrl = nextPageUrl;
|
2017-08-12 22:19:56 +02:00
|
|
|
this.errors = errors;
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public boolean hasNextPage() {
|
|
|
|
return nextPageUrl != null && !nextPageUrl.isEmpty();
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
2017-11-11 12:17:14 +01:00
|
|
|
|
2018-01-20 15:35:00 +01:00
|
|
|
public List<InfoItem> getNextItemsList() {
|
2018-02-24 22:20:50 +01:00
|
|
|
return infoItemList;
|
2017-11-11 12:17:14 +01:00
|
|
|
}
|
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
public String getNextPageUrl() {
|
|
|
|
return nextPageUrl;
|
2017-11-11 12:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<Throwable> getErrors() {
|
|
|
|
return errors;
|
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
2017-07-10 00:43:04 +02:00
|
|
|
}
|