removed commentsInfo from streamInfo
This commit is contained in:
parent
7ed0da0493
commit
0e86475891
|
@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.NewPipe;
|
|||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
|
||||
|
||||
public class CommentsInfo extends ListInfo<CommentsInfoItem>{
|
||||
|
@ -23,78 +24,45 @@ public class CommentsInfo extends ListInfo<CommentsInfoItem>{
|
|||
return getInfo(NewPipe.getServiceByUrl(url), url);
|
||||
}
|
||||
|
||||
private static CommentsInfo getInfo(StreamingService serviceByUrl, String url) throws ExtractionException, IOException {
|
||||
public static CommentsInfo getInfo(StreamingService serviceByUrl, String url) throws ExtractionException, IOException {
|
||||
return getInfo(serviceByUrl.getCommentsExtractor(url));
|
||||
}
|
||||
|
||||
private static CommentsInfo getInfo(CommentsExtractor commentsExtractor) throws IOException, ExtractionException {
|
||||
//for services which do not have a comments extractor
|
||||
if(null == commentsExtractor) {
|
||||
// for services which do not have a comments extractor
|
||||
if (null == commentsExtractor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
commentsExtractor.fetchPage();
|
||||
String name = commentsExtractor.getName();
|
||||
int serviceId = commentsExtractor.getServiceId();
|
||||
ListLinkHandler listUrlIdHandler = commentsExtractor.getUIHandler();
|
||||
CommentsInfo commentsInfo = new CommentsInfo(serviceId, listUrlIdHandler, name);
|
||||
commentsInfo.setCommentsExtractor(commentsExtractor);
|
||||
InfoItemsPage<CommentsInfoItem> initialCommentsPage = ExtractorHelper.getItemsPageOrLogError(commentsInfo,
|
||||
commentsExtractor);
|
||||
commentsInfo.setComments(new ArrayList<>());
|
||||
commentsInfo.getComments().addAll(initialCommentsPage.getItems());
|
||||
//tmp
|
||||
InfoItemsPage<CommentsInfoItem> initialCommentsPage = ExtractorHelper.getItemsPageOrLogError(commentsInfo,
|
||||
commentsExtractor);
|
||||
commentsInfo.setRelatedItems(initialCommentsPage.getItems());
|
||||
commentsInfo.setNextPageUrl(initialCommentsPage.getNextPageUrl());
|
||||
|
||||
commentsInfo.setHasMoreComments(initialCommentsPage.hasNextPage());
|
||||
commentsInfo.setNextCommentsPageUrl(initialCommentsPage.getNextPageUrl());
|
||||
|
||||
return commentsInfo;
|
||||
}
|
||||
|
||||
public static void loadMoreComments(CommentsInfo commentsInfo) {
|
||||
if (commentsInfo.hasMoreComments()) {
|
||||
if(null == commentsInfo.getCommentsExtractor()) {
|
||||
try {
|
||||
commentsInfo.setCommentsExtractor(NewPipe.getService(commentsInfo.getServiceId()).getCommentsExtractor(commentsInfo.getUrl()));
|
||||
commentsInfo.getCommentsExtractor().fetchPage();
|
||||
} catch (ExtractionException | IOException e) {
|
||||
commentsInfo.addError(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
InfoItemsPage<CommentsInfoItem> commentsPage = commentsInfo.getCommentsExtractor()
|
||||
.getPage(commentsInfo.getNextCommentsPageUrl());
|
||||
commentsInfo.getComments().addAll(commentsPage.getItems());
|
||||
commentsInfo.setHasMoreComments(commentsPage.hasNextPage());
|
||||
commentsInfo.setNextCommentsPageUrl(commentsPage.getNextPageUrl());
|
||||
} catch (IOException | ExtractionException e) {
|
||||
commentsInfo.addError(e);
|
||||
}
|
||||
public static InfoItemsPage<CommentsInfoItem> getMoreItems(CommentsInfo commentsInfo, String pageUrl)
|
||||
throws ExtractionException, IOException {
|
||||
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo, pageUrl);
|
||||
}
|
||||
|
||||
public static InfoItemsPage<CommentsInfoItem> getMoreItems(StreamingService service, CommentsInfo commentsInfo,
|
||||
String pageUrl) throws IOException, ExtractionException {
|
||||
if (null == commentsInfo.getCommentsExtractor()) {
|
||||
commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl()));
|
||||
commentsInfo.getCommentsExtractor().fetchPage();
|
||||
}
|
||||
return commentsInfo.getCommentsExtractor().getPage(pageUrl);
|
||||
}
|
||||
|
||||
private transient CommentsExtractor commentsExtractor;
|
||||
private List<CommentsInfoItem> comments;
|
||||
private boolean hasMoreComments;
|
||||
private String nextCommentsPageUrl;
|
||||
|
||||
public List<CommentsInfoItem> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(List<CommentsInfoItem> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public boolean hasMoreComments() {
|
||||
return hasMoreComments;
|
||||
}
|
||||
|
||||
public void setHasMoreComments(boolean hasMoreComments) {
|
||||
this.hasMoreComments = hasMoreComments;
|
||||
}
|
||||
|
||||
public CommentsExtractor getCommentsExtractor() {
|
||||
return commentsExtractor;
|
||||
|
@ -104,12 +72,4 @@ public class CommentsInfo extends ListInfo<CommentsInfoItem>{
|
|||
this.commentsExtractor = commentsExtractor;
|
||||
}
|
||||
|
||||
public String getNextCommentsPageUrl() {
|
||||
return nextCommentsPageUrl;
|
||||
}
|
||||
|
||||
public void setNextCommentsPageUrl(String nextCommentsPageUrl) {
|
||||
this.nextCommentsPageUrl = nextCommentsPageUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -265,12 +265,6 @@ public class StreamInfo extends Info {
|
|||
|
||||
streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
|
||||
|
||||
try {
|
||||
streamInfo.setCommentsInfo(CommentsInfo.getInfo(streamInfo.getUrl()));
|
||||
} catch (Exception e) {
|
||||
streamInfo.addError(e);
|
||||
}
|
||||
|
||||
return streamInfo;
|
||||
}
|
||||
|
||||
|
@ -298,8 +292,6 @@ public class StreamInfo extends Info {
|
|||
private StreamInfoItem nextVideo;
|
||||
private List<InfoItem> relatedStreams;
|
||||
|
||||
private CommentsInfo commentsInfo;
|
||||
|
||||
private long startPosition = 0;
|
||||
private List<Subtitles> subtitles;
|
||||
|
||||
|
@ -496,12 +488,4 @@ public class StreamInfo extends Info {
|
|||
this.subtitles = subtitles;
|
||||
}
|
||||
|
||||
public CommentsInfo getCommentsInfo() {
|
||||
return commentsInfo;
|
||||
}
|
||||
|
||||
public void setCommentsInfo(CommentsInfo commentsInfo) {
|
||||
this.commentsInfo = commentsInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.jsoup.helper.StringUtil;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
|
@ -15,7 +16,6 @@ import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
|||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||
|
||||
public class YoutubeCommentsExtractorTest {
|
||||
|
||||
|
@ -41,32 +41,19 @@ public class YoutubeCommentsExtractorTest {
|
|||
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommentsFromStreamInfo() throws IOException, ExtractionException {
|
||||
boolean result = false;
|
||||
StreamInfo streamInfo = StreamInfo.getInfo("https://www.youtube.com/watch?v=rrgFN3AxGfs");
|
||||
|
||||
result = findInComments(streamInfo.getCommentsInfo().getComments(), "i should really be in the top comment.lol");
|
||||
|
||||
while (streamInfo.getCommentsInfo().hasMoreComments() && !result) {
|
||||
CommentsInfo.loadMoreComments(streamInfo.getCommentsInfo());
|
||||
result = findInComments(streamInfo.getCommentsInfo().getComments(), "i should really be in the top comment.lol");
|
||||
}
|
||||
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
|
||||
boolean result = false;
|
||||
CommentsInfo commentsInfo = CommentsInfo.getInfo("https://www.youtube.com/watch?v=rrgFN3AxGfs");
|
||||
assertTrue("what the fuck am i doing with my life.wmv".equals(commentsInfo.getName()));
|
||||
result = findInComments(commentsInfo.getComments(), "i should really be in the top comment.lol");
|
||||
result = findInComments(commentsInfo.getRelatedItems(), "i should really be in the top comment.lol");
|
||||
|
||||
while (commentsInfo.hasMoreComments() && !result) {
|
||||
CommentsInfo.loadMoreComments(commentsInfo);
|
||||
result = findInComments(commentsInfo.getComments(), "i should really be in the top comment.lol");
|
||||
String nextPage = commentsInfo.getNextPageUrl();
|
||||
while (!StringUtil.isBlank(nextPage) && !result) {
|
||||
InfoItemsPage<CommentsInfoItem> moreItems = CommentsInfo.getMoreItems(YouTube, commentsInfo, nextPage);
|
||||
result = findInComments(moreItems.getItems(), "i should really be in the top comment.lol");
|
||||
nextPage = moreItems.getNextPageUrl();
|
||||
}
|
||||
|
||||
assertTrue(result);
|
||||
|
|
Loading…
Reference in New Issue