Skip to content

Commit e7aee0c

Browse files
authored
Merge pull request #807 from FireMasterK/no-commentsinfo-instance
Remove the need for a CommentsInfo instance in CommentsInfo.getMoreItems and fix PeertubeCommentsExtractorTest.Default test
2 parents d806984 + 60cc71e commit e7aee0c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,21 @@ public static CommentsInfo getInfo(final CommentsExtractor commentsExtractor)
5656
public static InfoItemsPage<CommentsInfoItem> getMoreItems(
5757
final CommentsInfo commentsInfo,
5858
final Page page) throws ExtractionException, IOException {
59-
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo, page);
59+
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo.getUrl(), page);
6060
}
6161

6262
public static InfoItemsPage<CommentsInfoItem> getMoreItems(
6363
final StreamingService service,
6464
final CommentsInfo commentsInfo,
6565
final Page page) throws IOException, ExtractionException {
66-
if (commentsInfo.getCommentsExtractor() == null) {
67-
commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl()));
68-
commentsInfo.getCommentsExtractor().fetchPage();
69-
}
70-
return commentsInfo.getCommentsExtractor().getPage(page);
66+
return getMoreItems(service, commentsInfo.getUrl(), page);
67+
}
68+
69+
public static InfoItemsPage<CommentsInfoItem> getMoreItems(
70+
final StreamingService service,
71+
final String url,
72+
final Page page) throws IOException, ExtractionException {
73+
return service.getCommentsExtractor(url).getPage(page);
7174
}
7275

7376
private transient CommentsExtractor commentsExtractor;

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,34 @@ public static class Default {
2828
public static void setUp() throws Exception {
2929
NewPipe.init(DownloaderTestImpl.getInstance());
3030
extractor = (PeertubeCommentsExtractor) PeerTube
31-
.getCommentsExtractor("https://framatube.org/videos/watch/04af977f-4201-4697-be67-a8d8cae6fa7a");
31+
.getCommentsExtractor("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d");
3232
}
3333

3434
@Test
3535
public void testGetComments() throws IOException, ExtractionException {
3636
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
37-
boolean result = findInComments(comments, "@root A great documentary on a great guy.");
37+
boolean result = findInComments(comments, "Cool.");
3838

3939
while (comments.hasNextPage() && !result) {
4040
comments = extractor.getPage(comments.getNextPage());
41-
result = findInComments(comments, "@root A great documentary on a great guy.");
41+
result = findInComments(comments, "Cool.");
4242
}
4343

4444
assertTrue(result);
4545
}
4646

4747
@Test
4848
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
49-
CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/a8ea95b8-0396-49a6-8f30-e25e25fb2828");
49+
CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/217eefeb-883d-45be-b7fc-a788ad8507d3");
5050
assertEquals("Comments", commentsInfo.getName());
5151

52-
boolean result = findInComments(commentsInfo.getRelatedItems(), "Loved it!!!");
52+
boolean result = findInComments(commentsInfo.getRelatedItems(), "Cool");
5353

5454
Page nextPage = commentsInfo.getNextPage();
5555
InfoItemsPage<CommentsInfoItem> moreItems = new InfoItemsPage<>(null, nextPage, null);
5656
while (moreItems.hasNextPage() && !result) {
5757
moreItems = CommentsInfo.getMoreItems(PeerTube, commentsInfo, nextPage);
58-
result = findInComments(moreItems.getItems(), "Loved it!!!");
58+
result = findInComments(moreItems.getItems(), "Cool");
5959
nextPage = moreItems.getNextPage();
6060
}
6161

0 commit comments

Comments
 (0)