diff --git a/src/renderer/helpers/api/invidious.js b/src/renderer/helpers/api/invidious.js index 19e74dac2027b..fa1566b24be97 100644 --- a/src/renderer/helpers/api/invidious.js +++ b/src/renderer/helpers/api/invidious.js @@ -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 @@ -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 @@ -276,6 +278,7 @@ export async function searchInvidiousChannel(channelId, query, page) { response.forEach((item) => { if (item.type === 'video') { + normalizeOneInvidiousVideoAttributes(item, channelId) setPublishedTimestamp(item) } }) @@ -314,6 +317,7 @@ export async function invidiousGetPlaylistInfo(playlistId) { id: playlistId, }) + normalizeManyInvidiousVideosAttributes(playlist.videos) setMultiplePublishedTimestamps(playlist.videos) return playlist @@ -522,6 +526,7 @@ export async function getInvidiousPopularFeed() { items.forEach((item) => { if (item.type === 'video' || item.type === 'shortVideo') { + normalizeOneInvidiousVideoAttributes(item) setPublishedTimestamp(item) } }) @@ -560,6 +565,7 @@ export async function getInvidiousSearchResults(query, page, searchSettings) { results.forEach((item) => { if (item.type === 'video') { + normalizeOneInvidiousVideoAttributes(item) setPublishedTimestamp(item) } }) @@ -825,6 +831,7 @@ export async function getHashtagInvidious(hashtag, page = 1) { } }) + normalizeManyInvidiousVideosAttributes(response.results) setMultiplePublishedTimestamps(response.results) return response.results @@ -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, diff --git a/src/renderer/helpers/api/local.js b/src/renderer/helpers/api/local.js index dacff30362d6f..610d0e6d8eba2 100644 --- a/src/renderer/helpers/api/local.js +++ b/src/renderer/helpers/api/local.js @@ -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, @@ -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),