diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java index a69b55f52..0d452f6fe 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -6,12 +6,10 @@ import java.util.List; import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.Subtitles; -import org.schabi.newpipe.extractor.comments.CommentsExtractor; -import org.schabi.newpipe.extractor.comments.CommentsInfoItem; +import org.schabi.newpipe.extractor.comments.CommentsInfo; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.utils.DashMpdParser; @@ -267,40 +265,15 @@ public class StreamInfo extends Info { streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor)); - CommentsExtractor commentsExtractor = null; try { - commentsExtractor = NewPipe.getService(streamInfo.getServiceId()).getCommentsExtractor(streamInfo.getUrl()); - streamInfo.setCommentsExtractor(commentsExtractor); + streamInfo.setCommentsInfo(CommentsInfo.getInfo(streamInfo.getUrl())); } catch (Exception e) { streamInfo.addError(e); } - if (null != commentsExtractor) { - InfoItemsPage initialCommentsPage = ExtractorHelper.getItemsPageOrLogError(streamInfo, - commentsExtractor); - streamInfo.setComments(new ArrayList<>()); - streamInfo.getComments().addAll(initialCommentsPage.getItems()); - streamInfo.setHasMoreComments(initialCommentsPage.hasNextPage()); - streamInfo.setNextCommentsPageUrl(initialCommentsPage.getNextPageUrl()); - } - return streamInfo; } - public static void loadMoreComments(StreamInfo streamInfo) { - if (streamInfo.hasMoreComments() && null != streamInfo.getCommentsExtractor()) { - try { - InfoItemsPage commentsPage = streamInfo.getCommentsExtractor() - .getPage(streamInfo.getNextCommentsPageUrl()); - streamInfo.getComments().addAll(commentsPage.getItems()); - streamInfo.setHasMoreComments(commentsPage.hasNextPage()); - streamInfo.setNextCommentsPageUrl(commentsPage.getNextPageUrl()); - } catch (IOException | ExtractionException e) { - streamInfo.addError(e); - } - } - } - private StreamType streamType; private String thumbnailUrl; private String uploadDate; @@ -325,10 +298,7 @@ public class StreamInfo extends Info { private StreamInfoItem nextVideo; private List relatedStreams; - private CommentsExtractor commentsExtractor; - private List comments; - private boolean hasMoreComments; - private String nextCommentsPageUrl; + private CommentsInfo commentsInfo; private long startPosition = 0; private List subtitles; @@ -526,36 +496,12 @@ public class StreamInfo extends Info { this.subtitles = subtitles; } - public List getComments() { - return comments; + public CommentsInfo getCommentsInfo() { + return commentsInfo; } - public void setComments(List comments) { - this.comments = comments; - } - - public boolean hasMoreComments() { - return hasMoreComments; - } - - public void setHasMoreComments(boolean hasMoreComments) { - this.hasMoreComments = hasMoreComments; - } - - public CommentsExtractor getCommentsExtractor() { - return commentsExtractor; - } - - public void setCommentsExtractor(CommentsExtractor commentsExtractor) { - this.commentsExtractor = commentsExtractor; - } - - public String getNextCommentsPageUrl() { - return nextCommentsPageUrl; - } - - public void setNextCommentsPageUrl(String nextCommentsPageUrl) { - this.nextCommentsPageUrl = nextCommentsPageUrl; + public void setCommentsInfo(CommentsInfo commentsInfo) { + this.commentsInfo = commentsInfo; } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java index cc56a21b8..ee13a15cc 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java @@ -47,11 +47,11 @@ public class YoutubeCommentsExtractorTest { boolean result = false; StreamInfo streamInfo = StreamInfo.getInfo("https://www.youtube.com/watch?v=rrgFN3AxGfs"); - result = findInComments(streamInfo.getComments(), "i should really be in the top comment.lol"); + result = findInComments(streamInfo.getCommentsInfo().getComments(), "i should really be in the top comment.lol"); - while (streamInfo.hasMoreComments() && !result) { - StreamInfo.loadMoreComments(streamInfo); - result = findInComments(streamInfo.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);