removed comment details form streamInfo. added commentsInfo instead

This commit is contained in:
Ritvik Saraf 2018-09-19 04:33:57 +05:30
parent ee239985ae
commit 4794e16dcb
2 changed files with 11 additions and 65 deletions

View File

@ -6,12 +6,10 @@ import java.util.List;
import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.Subtitles; import org.schabi.newpipe.extractor.Subtitles;
import org.schabi.newpipe.extractor.comments.CommentsExtractor; import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.utils.DashMpdParser; import org.schabi.newpipe.extractor.utils.DashMpdParser;
@ -267,40 +265,15 @@ public class StreamInfo extends Info {
streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor)); streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
CommentsExtractor commentsExtractor = null;
try { try {
commentsExtractor = NewPipe.getService(streamInfo.getServiceId()).getCommentsExtractor(streamInfo.getUrl()); streamInfo.setCommentsInfo(CommentsInfo.getInfo(streamInfo.getUrl()));
streamInfo.setCommentsExtractor(commentsExtractor);
} catch (Exception e) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
if (null != commentsExtractor) {
InfoItemsPage<CommentsInfoItem> initialCommentsPage = ExtractorHelper.getItemsPageOrLogError(streamInfo,
commentsExtractor);
streamInfo.setComments(new ArrayList<>());
streamInfo.getComments().addAll(initialCommentsPage.getItems());
streamInfo.setHasMoreComments(initialCommentsPage.hasNextPage());
streamInfo.setNextCommentsPageUrl(initialCommentsPage.getNextPageUrl());
}
return streamInfo; return streamInfo;
} }
public static void loadMoreComments(StreamInfo streamInfo) {
if (streamInfo.hasMoreComments() && null != streamInfo.getCommentsExtractor()) {
try {
InfoItemsPage<CommentsInfoItem> 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 StreamType streamType;
private String thumbnailUrl; private String thumbnailUrl;
private String uploadDate; private String uploadDate;
@ -325,10 +298,7 @@ public class StreamInfo extends Info {
private StreamInfoItem nextVideo; private StreamInfoItem nextVideo;
private List<InfoItem> relatedStreams; private List<InfoItem> relatedStreams;
private CommentsExtractor commentsExtractor; private CommentsInfo commentsInfo;
private List<CommentsInfoItem> comments;
private boolean hasMoreComments;
private String nextCommentsPageUrl;
private long startPosition = 0; private long startPosition = 0;
private List<Subtitles> subtitles; private List<Subtitles> subtitles;
@ -526,36 +496,12 @@ public class StreamInfo extends Info {
this.subtitles = subtitles; this.subtitles = subtitles;
} }
public List<CommentsInfoItem> getComments() { public CommentsInfo getCommentsInfo() {
return comments; return commentsInfo;
} }
public void setComments(List<CommentsInfoItem> comments) { public void setCommentsInfo(CommentsInfo commentsInfo) {
this.comments = comments; this.commentsInfo = commentsInfo;
}
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;
} }
} }

View File

@ -47,11 +47,11 @@ public class YoutubeCommentsExtractorTest {
boolean result = false; boolean result = false;
StreamInfo streamInfo = StreamInfo.getInfo("https://www.youtube.com/watch?v=rrgFN3AxGfs"); 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) { while (streamInfo.getCommentsInfo().hasMoreComments() && !result) {
StreamInfo.loadMoreComments(streamInfo); CommentsInfo.loadMoreComments(streamInfo.getCommentsInfo());
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");
} }
assertTrue(result); assertTrue(result);