Skip to content

Commit 02930d0

Browse files
committed
added comments test for invidious
1 parent a12c0e2 commit 02930d0

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeCommentsLinkHandlerFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
public class YoutubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {
1515

1616
private static final YoutubeCommentsLinkHandlerFactory instance = new YoutubeCommentsLinkHandlerFactory();
17-
private static final String ID_PATTERN = "([\\-a-zA-Z0-9_]{11})";
1817

1918
public static YoutubeCommentsLinkHandlerFactory getInstance() {
2019
return instance;

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.junit.BeforeClass;
55
import org.junit.Test;
66
import org.schabi.newpipe.DownloaderTestImpl;
7-
import org.schabi.newpipe.DownloaderTestImpl;
87
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
98
import org.schabi.newpipe.extractor.NewPipe;
109
import org.schabi.newpipe.extractor.comments.CommentsInfo;
@@ -21,17 +20,32 @@
2120

2221
public class YoutubeCommentsExtractorTest {
2322

24-
private static YoutubeCommentsExtractor extractor;
23+
private static final String urlYT = "https://www.youtube.com/watch?v=D00Au7k3i6o";
24+
private static final String urlInvidious = "https://invidio.us/watch?v=D00Au7k3i6o";
25+
private static final String urlInvidioush = "https://invidiou.sh/watch?v=D00Au7k3i6o";
26+
private static YoutubeCommentsExtractor extractorYT;
27+
private static YoutubeCommentsExtractor extractorInvidious;
28+
private static YoutubeCommentsExtractor extractorInvidioush;
2529

2630
@BeforeClass
2731
public static void setUp() throws Exception {
2832
NewPipe.init(DownloaderTestImpl.getInstance());
29-
extractor = (YoutubeCommentsExtractor) YouTube
30-
.getCommentsExtractor("https://www.invidio.us/watch?v=D00Au7k3i6o");
33+
extractorYT = (YoutubeCommentsExtractor) YouTube
34+
.getCommentsExtractor(urlYT);
35+
extractorInvidious = (YoutubeCommentsExtractor) YouTube
36+
.getCommentsExtractor(urlInvidious);
37+
extractorInvidioush = (YoutubeCommentsExtractor) YouTube
38+
.getCommentsExtractor(urlInvidioush);
3139
}
3240

3341
@Test
3442
public void testGetComments() throws IOException, ExtractionException {
43+
assertTrue(getCommentsHelper(extractorYT));
44+
assertTrue(getCommentsHelper(extractorInvidious));
45+
assertTrue(getCommentsHelper(extractorInvidioush));
46+
}
47+
48+
private boolean getCommentsHelper(YoutubeCommentsExtractor extractor) throws IOException, ExtractionException {
3549
boolean result;
3650
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
3751
result = findInComments(comments, "s1ck m3m3");
@@ -41,13 +55,20 @@ public void testGetComments() throws IOException, ExtractionException {
4155
result = findInComments(comments, "s1ck m3m3");
4256
}
4357

44-
assertTrue(result);
58+
return result;
59+
4560
}
4661

4762
@Test
4863
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
64+
assertTrue(getCommentsFromCommentsInfoHelper(urlYT));
65+
assertTrue(getCommentsFromCommentsInfoHelper(urlInvidious));
66+
assertTrue(getCommentsFromCommentsInfoHelper(urlInvidioush));
67+
}
68+
69+
private boolean getCommentsFromCommentsInfoHelper(String url) throws IOException, ExtractionException {
4970
boolean result = false;
50-
CommentsInfo commentsInfo = CommentsInfo.getInfo("https://www.invidio.us/watch?v=D00Au7k3i6o");
71+
CommentsInfo commentsInfo = CommentsInfo.getInfo(url);
5172
assertTrue("what the fuck am i doing with my life".equals(commentsInfo.getName()));
5273
result = findInComments(commentsInfo.getRelatedItems(), "s1ck m3m3");
5374

@@ -57,16 +78,15 @@ public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionExce
5778
result = findInComments(moreItems.getItems(), "s1ck m3m3");
5879
nextPage = moreItems.getNextPageUrl();
5980
}
60-
61-
assertTrue(result);
81+
return result;
6282
}
63-
83+
6484
@Test
6585
public void testGetCommentsAllData() throws IOException, ExtractionException {
66-
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
86+
InfoItemsPage<CommentsInfoItem> comments = extractorYT.getInitialPage();
6787

6888
DefaultTests.defaultTestListOfItems(YouTube.getServiceId(), comments.getItems(), comments.getErrors());
69-
for(CommentsInfoItem c: comments.getItems()) {
89+
for (CommentsInfoItem c : comments.getItems()) {
7090
assertFalse(StringUtil.isBlank(c.getAuthorEndpoint()));
7191
assertFalse(StringUtil.isBlank(c.getAuthorName()));
7292
assertFalse(StringUtil.isBlank(c.getAuthorThumbnail()));
@@ -86,8 +106,8 @@ private boolean findInComments(InfoItemsPage<CommentsInfoItem> comments, String
86106
}
87107

88108
private boolean findInComments(List<CommentsInfoItem> comments, String comment) {
89-
for(CommentsInfoItem c: comments) {
90-
if(c.getCommentText().contains(comment)) {
109+
for (CommentsInfoItem c : comments) {
110+
if (c.getCommentText().contains(comment)) {
91111
return true;
92112
}
93113
}

0 commit comments

Comments
 (0)