Merge pull request #628 from litetex/fix-broken-yt-liked-comments

Fix broken yt likes in comments
This commit is contained in:
bopol
2021-05-29 11:04:11 +02:00
committed by GitHub
25 changed files with 630 additions and 178 deletions

View File

@@ -13,10 +13,10 @@ import org.schabi.newpipe.extractor.utils.Utils;
import java.io.IOException;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
public class BandcampCommentsExtractorTest {
@@ -47,6 +47,7 @@ public class BandcampCommentsExtractorTest {
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertEquals(-1, c.getLikeCount());
assertTrue(Utils.isBlank(c.getTextualLikeCount()));
}
}
}

View File

@@ -75,7 +75,8 @@ public class PeertubeCommentsExtractorTest {
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() != -1);
assertEquals(-1, c.getLikeCount());
assertTrue(Utils.isBlank(c.getTextualLikeCount()));
}
}

View File

@@ -9,12 +9,14 @@ import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.services.DefaultTests;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsExtractor;
import org.schabi.newpipe.extractor.utils.Utils;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import static org.junit.Assert.assertEquals;
@@ -98,7 +100,7 @@ public class YoutubeCommentsExtractorTest {
assertNotNull(c.getUploadDate());
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() < 0);
assertTrue(c.getLikeCount() >= 0);
}
}
@@ -148,7 +150,7 @@ public class YoutubeCommentsExtractorTest {
assertNotNull(c.getUploadDate());
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() < 0);
assertTrue(c.getLikeCount() >= 0);
if (c.getCommentId().equals("Ugga_h1-EXdHB3gCoAEC")) { // comment without text
assertTrue(Utils.isBlank(c.getCommentText()));
} else {
@@ -191,7 +193,7 @@ public class YoutubeCommentsExtractorTest {
assertNotNull(c.getUploadDate());
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() < 0);
assertTrue(c.getLikeCount() >= 0);
assertFalse(Utils.isBlank(c.getCommentText()));
if (c.isHeartedByUploader()) {
heartedByUploader = true;
@@ -232,11 +234,76 @@ public class YoutubeCommentsExtractorTest {
assertNotNull(c.getUploadDate());
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() < 0);
assertTrue(c.getLikeCount() >= 0);
assertFalse(Utils.isBlank(c.getCommentText()));
}
assertTrue("First comment isn't pinned", comments.getItems().get(0).isPinned());
}
}
/**
* Checks if the likes/votes are handled correctly<br/>
* A pinned comment with >15K likes is used for the test
*/
public static class LikesVotes {
private final static String url = "https://www.youtube.com/watch?v=QqsLTNkzvaY";
private static YoutubeCommentsExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
YoutubeParsingHelper.resetClientVersionAndKey();
YoutubeParsingHelper.setNumberGenerator(new Random(1));
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "likes"));
extractor = (YoutubeCommentsExtractor) YouTube
.getCommentsExtractor(url);
extractor.fetchPage();
}
@Test
public void testGetCommentsFirst() throws IOException, ExtractionException {
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
CommentsInfoItem pinnedComment = comments.getItems().get(0);
assertTrue("First comment isn't pinned", pinnedComment.isPinned());
assertTrue("The first pinned comment has no likes", pinnedComment.getLikeCount() > 0);
assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualLikeCount()));
}
}
/**
* Checks if the vote count works localized<br/>
* A pinned comment with >15K likes is used for the test
*/
public static class LocalizedVoteCount {
private final static String url = "https://www.youtube.com/watch?v=QqsLTNkzvaY";
private static YoutubeCommentsExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
YoutubeParsingHelper.resetClientVersionAndKey();
YoutubeParsingHelper.setNumberGenerator(new Random(1));
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "localized_vote_count"));
extractor = (YoutubeCommentsExtractor) YouTube
.getCommentsExtractor(url);
// Force non english local here
extractor.forceLocalization(Localization.fromLocale(Locale.GERMANY));
extractor.fetchPage();
}
@Test
public void testGetCommentsFirst() throws IOException, ExtractionException {
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
CommentsInfoItem pinnedComment = comments.getItems().get(0);
assertTrue("First comment isn't pinned", pinnedComment.isPinned());
assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualLikeCount()));
}
}
}