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

82 lines
2.3 KiB
Java
Raw Normal View History

package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
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 {
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-26 16:19:58 +01:00
public ListExtractor(StreamingService service, String url) {
2017-08-06 22:20:15 +02:00
super(service, url);
}
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-26 15:55:27 +01:00
public abstract String getNextPageUrl() throws IOException, ExtractionException;
2017-08-06 22:20:15 +02:00
2018-02-26 15:55:27 +01:00
public abstract InfoItemPage getPage(final String nextPageUrl) throws IOException, ExtractionException;
2018-02-26 15:55:27 +01:00
public boolean hasNextPage() throws IOException, ExtractionException {
return getNextPageUrl() != null && !getNextPageUrl().isEmpty();
}
2018-02-26 15:55:27 +01: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
/**
* 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());
}
2018-02-24 22:20:50 +01:00
public InfoItemPage(List<InfoItem> infoItemList, String nextPageUrl, List<Throwable> errors) {
this.infoItemList = infoItemList;
this.nextPageUrl = nextPageUrl;
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
}
2018-02-26 16:49:15 +01:00
public List<InfoItem> getItemsList() {
2018-02-24 22:20:50 +01:00
return infoItemList;
}
2018-02-24 22:20:50 +01:00
public String getNextPageUrl() {
return nextPageUrl;
}
public List<Throwable> getErrors() {
return errors;
}
2017-08-06 22:20:15 +02:00
}
}