Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract published date and views for playlists with the local API #3767

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,47 @@ export function parseLocalPlaylistVideo(video) {
/** @type {import('youtubei.js').YTNodes.PlaylistVideo} */
const video_ = video

let viewCount = null

// the accessiblity label contains the full view count
// the video info only contains the short view count
if (video_.accessibility_label) {
const match = video_.accessibility_label.match(/([\d,.]+|no) views?$/i)

if (match) {
const count = match[1]

// as it's rare that a video has no views,
// checking the length allows us to avoid running toLowerCase unless we have to
if (count.length === 2 && count.toLowerCase() === 'no') {
viewCount = 0
} else {
const views = extractNumberFromString(count)

if (!isNaN(views)) {
viewCount = views
}
}
}
}

let publishedText = null

// normal videos have 3 text runs with the last one containing the published date
// live videos have 2 text runs with the number of people watching
// upcoming either videos don't have any info text or the number of people waiting,
// but we have the premiere date for those, so we don't need the published date
if (video_.video_info.runs && video_.video_info.runs.length === 3) {
publishedText = video_.video_info.runs[2].text
}

return {
videoId: video_.id,
title: video_.title.text,
author: video_.author.name,
authorId: video_.author.id,
viewCount,
publishedText,
lengthSeconds: isNaN(video_.duration.seconds) ? '' : video_.duration.seconds,
liveNow: video_.is_live,
isUpcoming: video_.is_upcoming,
Expand Down