Skip to content

Commit

Permalink
fix: rating shouldn't be NaN when vote is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Jul 20, 2023
1 parent 88ebf8b commit 9f26392
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/scrapers/pages/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ export function parseByDom(html: string, $: CheerioAPI) {
const title = $('head > title').first().text().replace(' - Pornhub.com', '')
const viewsText = $('span.count').text() || '0'
const views = parseReadableNumber(viewsText)
const totalVote = voteUp + voteDown
const vote = {
up: voteUp,
down: voteDown,
total: voteUp + voteDown,
rating: Math.round(voteUp / (voteUp + voteDown) * 100) / 100,
total: totalVote,
rating: totalVote === 0 ? 0 : Math.round(voteUp / totalVote * 100) / 100,
}
const premium = $('.video-wrapper .ph-icon-badge-premium').length !== 0
const thumb = getAttribute<string>($('.thumbnail img'), 'src', '')
Expand Down

0 comments on commit 9f26392

Please sign in to comment.