Skip to content

Commit

Permalink
Add support for CommentViews in video comments (#4806)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Apr 2, 2024
1 parent 52e605d commit 455216c
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ export function mapLocalFormat(format) {
}

/**
* @param {import('youtubei.js').YTNodes.Comment} comment
* @param {import('youtubei.js').YTNodes.Comment|import('youtubei.js').YTNodes.CommentView} comment
* @param {import('youtubei.js').YTNodes.CommentThread} commentThread
*/
export function parseLocalComment(comment, commentThread = undefined) {
Expand All @@ -1056,26 +1056,48 @@ export function parseLocalComment(comment, commentThread = undefined) {
replyToken = commentThread
}

return {
const parsed = {
dataType: 'local',
authorLink: comment.author.id,
author: comment.author.name,
authorId: comment.author.id,
authorThumb: comment.author.best_thumbnail.url,
isPinned: comment.is_pinned,
isOwner: comment.author_is_channel_owner,
isMember: comment.is_member,
memberIconUrl: comment.is_member ? comment.sponsor_comment_badge.custom_badge[0].url : '',
isOwner: !!comment.author_is_channel_owner,
isMember: !!comment.is_member,
text: Autolinker.link(parseLocalTextRuns(comment.content.runs, 16, { looseChannelNameDetection: true })),
time: toLocalePublicationString({ publishText: comment.published.text.replace('(edited)', '').trim() }),
likes: comment.vote_count,
isHearted: comment.is_hearted,
numReplies: comment.reply_count,
isHearted: !!comment.is_hearted,
hasOwnerReplied,
replyToken,
showReplies: false,
replies: []
replies: [],

// default values for the properties set below
memberIconUrl: '',
time: '',
likes: 0,
numReplies: 0
}

if (comment.type === 'Comment') {
/** @type {import('youtubei.js').YTNodes.Comment} */
const comment_ = comment

parsed.memberIconUrl = comment_.is_member ? comment_.sponsor_comment_badge.custom_badge[0].url : ''
parsed.time = toLocalePublicationString({ publishText: comment_.published.text.replace('(edited)', '').trim() })
parsed.likes = comment_.vote_count
parsed.numReplies = comment_.reply_count
} else {
/** @type {import('youtubei.js').YTNodes.CommentView} */
const commentView = comment

parsed.memberIconUrl = commentView.is_member ? commentView.member_badge.url : ''
parsed.time = toLocalePublicationString({ publishText: commentView.published_time.replace('(edited)', '').trim() })
parsed.likes = commentView.like_count
parsed.numReplies = parseLocalSubscriberCount(commentView.reply_count)
}

return parsed
}

/**
Expand Down

0 comments on commit 455216c

Please sign in to comment.