Skip to content
Merged
Show file tree
Hide file tree
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
93 changes: 76 additions & 17 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,52 @@ function parseLockupView(lockupView, channelId = undefined, channelName = undefi
videoCount: extractNumberFromString(thumbnailOverlayBadgeView.badges[0].text)
}
}
case 'VIDEO': {
let publishedText
let lengthSeconds = ''
let liveNow = false

/** @type {YTNodes.ThumbnailOverlayBadgeView | undefined} */
const thumbnailOverlayBadgeView = lockupView.content_image?.overlays?.firstOfType(YTNodes.ThumbnailOverlayBadgeView)

if (thumbnailOverlayBadgeView) {
if (thumbnailOverlayBadgeView.badges.some(badge => badge.badge_style === 'THUMBNAIL_OVERLAY_BADGE_STYLE_LIVE')) {
liveNow = true
} else {
const durationBadge = thumbnailOverlayBadgeView.badges.find(badge => /^[\d:]+$/.test(badge.text))

if (durationBadge) {
lengthSeconds = Utils.timeToSeconds(durationBadge.text)
}

publishedText = lockupView.metadata.metadata?.metadata_rows[1].metadata_parts?.[1].text?.text
}
}

let viewCount = null

const viewsText = lockupView.metadata.metadata?.metadata_rows[1].metadata_parts?.[0].text?.text

if (viewsText) {
const views = parseLocalSubscriberCount(viewsText)

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

return {
type: 'video',
videoId: lockupView.content_id,
title: lockupView.metadata.title.text,
author: lockupView.metadata.metadata?.metadata_rows[0].metadata_parts?.[0].text?.text,
authorId: lockupView.metadata.image?.renderer_context?.command_context?.on_tap?.payload.browseId,
viewCount,
published: calculatePublishedDate(publishedText, liveNow),
lengthSeconds,
liveNow
}
}
default:
console.warn(`Unknown lockup content type: ${lockupView.content_type}`, lockupView)
return null
Expand Down Expand Up @@ -1338,28 +1384,41 @@ function parseListItem(item) {
}

/**
* @param {import('youtubei.js').YTNodes.CompactVideo} video
* @param {YTNodes.CompactVideo | YTNodes.CompactMovie | YTNodes.LockupView} video
*/
export function parseLocalWatchNextVideo(video) {
let publishedText
if (video.is(YTNodes.CompactMovie)) {
return {
type: 'video',
videoId: video.id,
title: video.title.text,
author: video.author.name,
authorId: video.author.id,
lengthSeconds: video.duration.seconds
}
} else if (video.is(YTNodes.LockupView)) {
return parseLockupView(video)
} else {
let publishedText

if (video.published != null && !video.published.isEmpty()) {
publishedText = video.published.text
}
if (video.published != null && !video.published.isEmpty()) {
publishedText = video.published.text
}

const published = calculatePublishedDate(publishedText, video.is_live, video.is_premiere)
const published = calculatePublishedDate(publishedText, video.is_live, video.is_premiere)

return {
type: 'video',
videoId: video.video_id,
title: video.title.text,
author: video.author.name,
authorId: video.author.id,
viewCount: video.view_count == null ? null : extractNumberFromString(video.view_count.text),
published,
lengthSeconds: isNaN(video.duration.seconds) ? '' : video.duration.seconds,
liveNow: video.is_live,
isUpcoming: video.is_premiere
return {
type: 'video',
videoId: video.video_id,
title: video.title.text,
author: video.author.name,
authorId: video.author.id,
viewCount: video.view_count == null ? null : extractNumberFromString(video.view_count.text),
published,
lengthSeconds: isNaN(video.duration.seconds) ? '' : video.duration.seconds,
liveNow: video.is_live,
isUpcoming: video.is_premiere
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ export default defineComponent({
this.isFamilyFriendly = result.basic_info.is_family_safe

const recommendedVideos = result.watch_next_feed
?.filter((item) => item.type === 'CompactVideo' || item.type === 'CompactMovie')
?.filter((item) => {
return item.type === 'CompactVideo' || item.type === 'CompactMovie' ||
(item.type === 'LockupView' && item.content_type === 'VIDEO')
})
.map(parseLocalWatchNextVideo) ?? []

// place watched recommended videos last
Expand Down