From 60cc71e944da3e691ba61a2e5d026d808886fc5a Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 3 Mar 2022 11:04:30 +0000 Subject: [PATCH] Remove the need for a CommentsInfo instance. --- .../newpipe/extractor/comments/CommentsInfo.java | 15 +++++++++------ .../peertube/PeertubeCommentsExtractorTest.java | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java index 439ade431..a280500c8 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java @@ -56,18 +56,21 @@ public class CommentsInfo extends ListInfo { public static InfoItemsPage getMoreItems( final CommentsInfo commentsInfo, final Page page) throws ExtractionException, IOException { - return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo, page); + return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo.getUrl(), page); } public static InfoItemsPage getMoreItems( final StreamingService service, final CommentsInfo commentsInfo, final Page page) throws IOException, ExtractionException { - if (commentsInfo.getCommentsExtractor() == null) { - commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl())); - commentsInfo.getCommentsExtractor().fetchPage(); - } - return commentsInfo.getCommentsExtractor().getPage(page); + return getMoreItems(service, commentsInfo.getUrl(), page); + } + + public static InfoItemsPage getMoreItems( + final StreamingService service, + final String url, + final Page page) throws IOException, ExtractionException { + return service.getCommentsExtractor(url).getPage(page); } private transient CommentsExtractor commentsExtractor; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java index 8dc74c98c..9955fe1c3 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java @@ -28,17 +28,17 @@ public class PeertubeCommentsExtractorTest { public static void setUp() throws Exception { NewPipe.init(DownloaderTestImpl.getInstance()); extractor = (PeertubeCommentsExtractor) PeerTube - .getCommentsExtractor("https://framatube.org/videos/watch/04af977f-4201-4697-be67-a8d8cae6fa7a"); + .getCommentsExtractor("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d"); } @Test public void testGetComments() throws IOException, ExtractionException { InfoItemsPage comments = extractor.getInitialPage(); - boolean result = findInComments(comments, "@root A great documentary on a great guy."); + boolean result = findInComments(comments, "Cool."); while (comments.hasNextPage() && !result) { comments = extractor.getPage(comments.getNextPage()); - result = findInComments(comments, "@root A great documentary on a great guy."); + result = findInComments(comments, "Cool."); } assertTrue(result); @@ -46,16 +46,16 @@ public class PeertubeCommentsExtractorTest { @Test public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException { - CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/a8ea95b8-0396-49a6-8f30-e25e25fb2828"); + CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/217eefeb-883d-45be-b7fc-a788ad8507d3"); assertEquals("Comments", commentsInfo.getName()); - boolean result = findInComments(commentsInfo.getRelatedItems(), "Loved it!!!"); + boolean result = findInComments(commentsInfo.getRelatedItems(), "Cool"); Page nextPage = commentsInfo.getNextPage(); InfoItemsPage moreItems = new InfoItemsPage<>(null, nextPage, null); while (moreItems.hasNextPage() && !result) { moreItems = CommentsInfo.getMoreItems(PeerTube, commentsInfo, nextPage); - result = findInComments(moreItems.getItems(), "Loved it!!!"); + result = findInComments(moreItems.getItems(), "Cool"); nextPage = moreItems.getNextPage(); }