Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
isVerified and isOfficialArtist (#22)
Browse files Browse the repository at this point in the history
* Added isVerified, isOfficialArtist and fixed broken Jest Tests

* Added new fields to ReadMe
  • Loading branch information
GilgusMaximus authored Jun 25, 2021
1 parent d7b19dd commit e84c9e8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ The data is returned as a list of objects (seen below).
isOwner: Boolean, // If the video channel made the comment
isHearted: Boolean, // If the video channel hearted the comment
isPinned: Boolean, // If the video channel pinned the comment
isVerified: Boolean,
isOfficialArtist: Boolean,
hasOwnerReplied: Boolean, // If the video channel replied to the comment
replyToken: String // The continuation token needed for getCommentReplies()
}],
Expand Down Expand Up @@ -120,6 +122,8 @@ The data is returned as a list of objects (seen below).
isOwner: Boolean, // If the video channel made the comment
isHearted: Boolean, // If the video channel hearted the comment
isPinned: false,
isVerified: Boolean,
isOfficialArtist: Boolean,
hasOwnerReplied: false,
replyToken: null
}],
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yt-comment-scraper",
"version": "5.1.0",
"name": "@freetube/yt-comment-scraper",
"version": "5.2.1",
"description": "Scrapes the comments of any YouTube video without YouTube API access. Uses the default YouTube Ajax calls to get the comment data.",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/htmlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class HtmlParser {
const heartBadge = comment.actionButtons.commentActionButtonsRenderer.creatorHeart
const isOwner = comment.authorIsChannelOwner
const isPinned = comment.pinnedCommentBadge ? true : false
const isVerified = ('authorCommentBadge' in comment && comment.authorCommentBadge.authorCommentBadgeRenderer.icon.iconType === "CHECK_CIRCLE_THICK")
const isOfficialArtist = ('authorCommentBadge' in comment && comment.authorCommentBadge.authorCommentBadgeRenderer.icon.iconType === "OFFICIAL_ARTIST_BADGE")


if (typeof heartBadge !== 'undefined') {
isHearted = heartBadge.creatorHeartRenderer.isHearted
Expand Down Expand Up @@ -53,7 +56,9 @@ class HtmlParser {
hasOwnerReplied: false,
time: publishedText,
edited: isEdited,
replyToken: null
replyToken: null,
isVerified: isVerified,
isOfficialArtist: isOfficialArtist
}

if (comment.replyCount > 0) {
Expand Down
20 changes: 9 additions & 11 deletions test/scraper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ describe('Standalone Mode: Comment Testing', () => {

test('Scrape top video comments of first page', () => {
const parameters = {videoId: 'oBLQmE-nG60', setCookie: true, sortByNewest: false};
ytcm.getComments(parameters).then((data) => {
return ytcm.getComments(parameters).then((data) => {
expect(data.comments).toHaveLength(20);
});
});

test('Scrape newest video comments of first page', () => {
const parameters = {videoId: 'oBLQmE-nG60', setCookie: true, sortByNewest: true};
ytcm.getComments(parameters).then((data) => {
return ytcm.getComments(parameters).then((data) => {
expect(data.comments).toHaveLength(20);
});
});

test('Scrape newest video comments second page', () => {
let parameters = {videoId: 'oBLQmE-nG60', setCookie: true, sortByNewest: true, continuation: null};
ytcm.getComments(parameters).then((data) => {
return ytcm.getComments(parameters).then((data) => {
parameters["continuation"] = data.continuation;
ytcm.getComments(parameters).then((data) => {
expect(data.comments).not.toHaveLength(0);
Expand All @@ -31,15 +31,14 @@ describe('Standalone Mode: Comment Testing', () => {
test('Scrape top replies of first page', () => {
const parameters = {videoId: 'oBLQmE-nG60', setCookie: true, sortByNewest: false};
// This test first gets comments of the video with above Id
ytcm.getComments(parameters).then((data) => {
return ytcm.getComments(parameters).then((data) => {
for (let i = 0; i < data.comments.length; i++) {
// The test searches for a comment which does have at least 1 reply and then ask for the replies
if (data.comments[i].numReplies > 0) {
const replyParameters = {videoId: 'oBLQmE-nG60', replyToken: data.comments[i].replyToken, setCookie: true};
ytcm.getCommentReplies(replyParameters).then((replyData) => {
return ytcm.getCommentReplies(replyParameters).then((replyData) => {
expect(replyData.comments).toHaveLength(10);
});
break
}
}
});
Expand All @@ -48,26 +47,25 @@ describe('Standalone Mode: Comment Testing', () => {
test('Scrape second batch of top replies of first page', () => {
const parameters = {videoId: 'oBLQmE-nG60', setCookie: true, sortByNewest: false};
// This test first gets comments of the video with above Id
ytcm.getComments(parameters).then((data) => {
return ytcm.getComments(parameters).then((data) => {
for (let i = 0; i < data.comments.length; i++) {
// The test searches for a comment which does have at least 1 reply and then ask for the replies
if (data.comments[i].numReplies > 0) {
let replyParameters = {videoId: 'oBLQmE-nG60', replyToken: data.comments[i].replyToken, setCookie: true};
ytcm.getCommentReplies(replyParameters).then((replyData) => {
return ytcm.getCommentReplies(replyParameters).then((replyData) => {
replyParameters.replyToken = replyData.continuation;
ytcm.getCommentReplies(replyParameters).then((replyData) => {
return ytcm.getCommentReplies(replyParameters).then((replyData) => {
expect(replyData.comments).not.toHaveLength(0);
})
});
break
}
}
});
});

test('Scrape video without comments', () => {
const parameters = {videoId: 'Bj-3M-KqZsI', setCookie: true, sortByNewest: false};
ytcm.getComments(parameters).then((data) => {
return ytcm.getComments(parameters).then((data) => {
expect(data.comments).toHaveLength(0);
});
});
Expand Down

0 comments on commit e84c9e8

Please sign in to comment.