Remove the need for a CommentsInfo instance.

This commit is contained in:
FireMasterK 2022-03-03 11:04:30 +00:00
parent 3a6269bca6
commit 60cc71e944
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
2 changed files with 15 additions and 12 deletions

View File

@ -56,18 +56,21 @@ public class CommentsInfo extends ListInfo<CommentsInfoItem> {
public static InfoItemsPage<CommentsInfoItem> getMoreItems( public static InfoItemsPage<CommentsInfoItem> getMoreItems(
final CommentsInfo commentsInfo, final CommentsInfo commentsInfo,
final Page page) throws ExtractionException, IOException { 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<CommentsInfoItem> getMoreItems( public static InfoItemsPage<CommentsInfoItem> getMoreItems(
final StreamingService service, final StreamingService service,
final CommentsInfo commentsInfo, final CommentsInfo commentsInfo,
final Page page) throws IOException, ExtractionException { final Page page) throws IOException, ExtractionException {
if (commentsInfo.getCommentsExtractor() == null) { return getMoreItems(service, commentsInfo.getUrl(), page);
commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl())); }
commentsInfo.getCommentsExtractor().fetchPage();
} public static InfoItemsPage<CommentsInfoItem> getMoreItems(
return commentsInfo.getCommentsExtractor().getPage(page); final StreamingService service,
final String url,
final Page page) throws IOException, ExtractionException {
return service.getCommentsExtractor(url).getPage(page);
} }
private transient CommentsExtractor commentsExtractor; private transient CommentsExtractor commentsExtractor;

View File

@ -28,17 +28,17 @@ public class PeertubeCommentsExtractorTest {
public static void setUp() throws Exception { public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance()); NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (PeertubeCommentsExtractor) PeerTube 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 @Test
public void testGetComments() throws IOException, ExtractionException { public void testGetComments() throws IOException, ExtractionException {
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
boolean result = findInComments(comments, "@root A great documentary on a great guy."); boolean result = findInComments(comments, "Cool.");
while (comments.hasNextPage() && !result) { while (comments.hasNextPage() && !result) {
comments = extractor.getPage(comments.getNextPage()); comments = extractor.getPage(comments.getNextPage());
result = findInComments(comments, "@root A great documentary on a great guy."); result = findInComments(comments, "Cool.");
} }
assertTrue(result); assertTrue(result);
@ -46,16 +46,16 @@ public class PeertubeCommentsExtractorTest {
@Test @Test
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException { 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()); assertEquals("Comments", commentsInfo.getName());
boolean result = findInComments(commentsInfo.getRelatedItems(), "Loved it!!!"); boolean result = findInComments(commentsInfo.getRelatedItems(), "Cool");
Page nextPage = commentsInfo.getNextPage(); Page nextPage = commentsInfo.getNextPage();
InfoItemsPage<CommentsInfoItem> moreItems = new InfoItemsPage<>(null, nextPage, null); InfoItemsPage<CommentsInfoItem> moreItems = new InfoItemsPage<>(null, nextPage, null);
while (moreItems.hasNextPage() && !result) { while (moreItems.hasNextPage() && !result) {
moreItems = CommentsInfo.getMoreItems(PeerTube, commentsInfo, nextPage); moreItems = CommentsInfo.getMoreItems(PeerTube, commentsInfo, nextPage);
result = findInComments(moreItems.getItems(), "Loved it!!!"); result = findInComments(moreItems.getItems(), "Cool");
nextPage = moreItems.getNextPage(); nextPage = moreItems.getNextPage();
} }