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

Commit

Permalink
Adjusted votecount to new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
GilgusMaximus committed May 22, 2021
1 parent 9394878 commit dc34235
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yt-comment-scraper",
"version": "4.0.1",
"version": "4.0.2",
"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
11 changes: 10 additions & 1 deletion src/htmlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HtmlParser {
const authorId = comment.authorEndpoint.browseEndpoint.browseId
const authorName = comment.authorText.simpleText
const authorThumbnails = comment.authorThumbnail.thumbnails
const likes = comment.likeCount
const likes = this.parseShortedNumberString(comment.voteCount.simpleText.split(' ')[0])
const numReplies = comment.replyCount ? comment.replyCount : 0
const publishedTimeText = comment.publishedTimeText.runs[0].text
const publishedText = publishedTimeText.replace('(edited)', '').trim()
Expand Down Expand Up @@ -62,6 +62,15 @@ class HtmlParser {

return comments
}
static parseShortedNumberString(string) {
const numberMultiplier = string.charAt(string.length-1).toLowerCase()
switch (numberMultiplier){
case 'k':
return Number(string.substring(0, string.length-1) * 1000)
case 'm':
return Number(string.substring(0, string.length-1) * 1000000)
}
}
}

module.exports = HtmlParser

0 comments on commit dc34235

Please sign in to comment.