Skip to content
Open
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
29 changes: 29 additions & 0 deletions src/renderer/helpers/api/invidious.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export async function getInvidiousChannelVideos(channelId, sortBy, continuation)
/** @type {{continuation: string?, videos: InvidiousVideoType[]}} */
const response = await getInvidiousChannelTab('videos', channelId, continuation, sortBy)

normalizeManyInvidiousVideosAttributes(response.videos, channelId)
setMultiplePublishedTimestamps(response.videos)

return response
Expand Down Expand Up @@ -215,6 +216,7 @@ export async function getInvidiousChannelLive(channelId, sortBy, continuation) {
/** @type {{continuation: string?, videos: InvidiousVideoType[]}} */
const response = await getInvidiousChannelTab('streams', channelId, continuation, sortBy)

normalizeManyInvidiousVideosAttributes(response.videos, channelId)
setMultiplePublishedTimestamps(response.videos)

return response
Expand Down Expand Up @@ -276,6 +278,7 @@ export async function searchInvidiousChannel(channelId, query, page) {

response.forEach((item) => {
if (item.type === 'video') {
normalizeOneInvidiousVideoAttributes(item, channelId)
setPublishedTimestamp(item)
}
})
Expand Down Expand Up @@ -314,6 +317,7 @@ export async function invidiousGetPlaylistInfo(playlistId) {
id: playlistId,
})

normalizeManyInvidiousVideosAttributes(playlist.videos)
setMultiplePublishedTimestamps(playlist.videos)

return playlist
Expand Down Expand Up @@ -522,6 +526,7 @@ export async function getInvidiousPopularFeed() {

items.forEach((item) => {
if (item.type === 'video' || item.type === 'shortVideo') {
normalizeOneInvidiousVideoAttributes(item)
setPublishedTimestamp(item)
}
})
Expand Down Expand Up @@ -560,6 +565,7 @@ export async function getInvidiousSearchResults(query, page, searchSettings) {

results.forEach((item) => {
if (item.type === 'video') {
normalizeOneInvidiousVideoAttributes(item)
setPublishedTimestamp(item)
}
})
Expand Down Expand Up @@ -825,6 +831,7 @@ export async function getHashtagInvidious(hashtag, page = 1) {
}
})

normalizeManyInvidiousVideosAttributes(response.results)
setMultiplePublishedTimestamps(response.results)

return response.results
Expand Down Expand Up @@ -942,6 +949,28 @@ export function mapInvidiousLegacyFormat(format) {
}
}

/**
* @param {{
* authorId: string | null,
* }[]} videos
* @param {string|null} [fallbackAuthorId]
*/
function normalizeManyInvidiousVideosAttributes(videos, fallbackAuthorId = null) {
const actualFallbackAuthorId = fallbackAuthorId === '' ? null : fallbackAuthorId

videos.forEach((v) => normalizeOneInvidiousVideoAttributes(v, actualFallbackAuthorId))
}

/**
* @param {{
* authorId: string | null,
* }} video
* @param {string|null} [fallbackAuthorId]
*/
function normalizeOneInvidiousVideoAttributes(video, fallbackAuthorId = null) {
if (video.authorId === '') video.authorId = fallbackAuthorId
}

/**
* @param {{
* liveNow: boolean,
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ export function parseLocalPlaylistVideo(video) {
videoId: video_.id,
title: video_.title.text,
author: video_.author.name,
authorId: video_.author.id,
authorId: video_.author?.id !== 'N/A' ? video_.author?.id : null,
viewCount,
published,
lengthSeconds: isNaN(video_.duration.seconds) ? '' : video_.duration.seconds,
Expand Down Expand Up @@ -1387,7 +1387,7 @@ export function parseLocalListVideo(item, channelId, channelName) {
videoId: video.video_id,
title: video.title.text,
author: video.author?.name ?? channelName,
authorId: video.author?.id ?? channelId,
authorId: (video.author?.id != null && video.author?.id !== 'N/A') ? video.author?.id : channelId,
viewCount: video.views.text == null ? null : extractNumberFromString(video.views.text),
published,
lengthSeconds: isLive ? '' : Utils.timeToSeconds(video.duration.text),
Expand Down