NewPipeExtractor/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java

73 lines
3.1 KiB
Java
Raw Normal View History

2018-08-20 00:52:19 +02:00
package org.schabi.newpipe.extractor.comments;
2018-09-19 00:52:23 +02:00
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
2018-08-20 00:52:19 +02:00
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
2020-04-15 14:09:46 +02:00
import org.schabi.newpipe.extractor.Page;
2018-08-20 00:52:19 +02:00
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
2018-09-19 00:52:23 +02:00
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
2018-08-20 00:52:19 +02:00
import java.io.IOException;
public class CommentsInfo extends ListInfo<CommentsInfoItem> {
private CommentsInfo(int serviceId, ListLinkHandler listUrlIdHandler, String name) {
super(serviceId, listUrlIdHandler, name);
}
2018-08-20 00:52:19 +02:00
public static CommentsInfo getInfo(String url) throws IOException, ExtractionException {
2018-08-20 00:52:19 +02:00
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static CommentsInfo getInfo(StreamingService serviceByUrl, String url) throws ExtractionException, IOException {
return getInfo(serviceByUrl.getCommentsExtractor(url));
}
2018-08-20 00:52:19 +02:00
2018-09-19 00:52:23 +02:00
private static CommentsInfo getInfo(CommentsExtractor commentsExtractor) throws IOException, ExtractionException {
2018-09-22 20:06:41 +02:00
// for services which do not have a comments extractor
if (null == commentsExtractor) {
2018-09-19 00:52:23 +02:00
return null;
}
2018-09-22 20:06:41 +02:00
2018-09-19 00:52:23 +02:00
commentsExtractor.fetchPage();
String name = commentsExtractor.getName();
int serviceId = commentsExtractor.getServiceId();
2018-09-29 09:49:00 +02:00
ListLinkHandler listUrlIdHandler = commentsExtractor.getLinkHandler();
2018-09-19 00:52:23 +02:00
CommentsInfo commentsInfo = new CommentsInfo(serviceId, listUrlIdHandler, name);
commentsInfo.setCommentsExtractor(commentsExtractor);
2018-09-22 20:06:41 +02:00
InfoItemsPage<CommentsInfoItem> initialCommentsPage = ExtractorHelper.getItemsPageOrLogError(commentsInfo,
commentsExtractor);
2018-09-22 11:25:59 +02:00
commentsInfo.setRelatedItems(initialCommentsPage.getItems());
2020-04-15 14:09:46 +02:00
commentsInfo.setNextPage(initialCommentsPage.getNextPage());
2018-09-22 20:06:41 +02:00
2018-09-19 00:52:23 +02:00
return commentsInfo;
}
2020-04-15 14:09:46 +02:00
public static InfoItemsPage<CommentsInfoItem> getMoreItems(CommentsInfo commentsInfo, Page page)
2018-09-22 20:06:41 +02:00
throws ExtractionException, IOException {
2020-04-15 14:09:46 +02:00
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo, page);
2018-09-22 20:06:41 +02:00
}
2018-09-22 20:06:41 +02:00
public static InfoItemsPage<CommentsInfoItem> getMoreItems(StreamingService service, CommentsInfo commentsInfo,
2020-04-15 14:09:46 +02:00
Page page) throws IOException, ExtractionException {
2018-09-22 20:06:41 +02:00
if (null == commentsInfo.getCommentsExtractor()) {
commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl()));
commentsInfo.getCommentsExtractor().fetchPage();
2018-09-19 00:52:23 +02:00
}
2020-04-15 14:09:46 +02:00
return commentsInfo.getCommentsExtractor().getPage(page);
2018-09-19 00:52:23 +02:00
}
2018-09-19 00:52:23 +02:00
private transient CommentsExtractor commentsExtractor;
public CommentsExtractor getCommentsExtractor() {
return commentsExtractor;
}
public void setCommentsExtractor(CommentsExtractor commentsExtractor) {
this.commentsExtractor = commentsExtractor;
}
2018-08-20 00:52:19 +02:00
}