Skip to content

Commit 9af908f

Browse files
committed
! Fix cross channel videos link sometimes broken (IV API
1 parent a16205d commit 9af908f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/renderer/helpers/api/invidious.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export async function getInvidiousChannelVideos(channelId, sortBy, continuation)
181181
/** @type {{continuation: string?, videos: InvidiousVideoType[]}} */
182182
const response = await getInvidiousChannelTab('videos', channelId, continuation, sortBy)
183183

184+
normalizeManyInvidiousVideosAttributes(response.videos, channelId)
184185
setMultiplePublishedTimestamps(response.videos)
185186

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

219+
normalizeManyInvidiousVideosAttributes(response.videos, channelId)
218220
setMultiplePublishedTimestamps(response.videos)
219221

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

277279
response.forEach((item) => {
278280
if (item.type === 'video') {
281+
normalizeOneInvidiousVideoAttributes(item, channelId)
279282
setPublishedTimestamp(item)
280283
}
281284
})
@@ -314,6 +317,7 @@ export async function invidiousGetPlaylistInfo(playlistId) {
314317
id: playlistId,
315318
})
316319

320+
normalizeManyInvidiousVideosAttributes(playlist.videos)
317321
setMultiplePublishedTimestamps(playlist.videos)
318322

319323
return playlist
@@ -522,6 +526,7 @@ export async function getInvidiousPopularFeed() {
522526

523527
items.forEach((item) => {
524528
if (item.type === 'video' || item.type === 'shortVideo') {
529+
normalizeOneInvidiousVideoAttributes(item)
525530
setPublishedTimestamp(item)
526531
}
527532
})
@@ -559,6 +564,7 @@ export async function getInvidiousTrending(tab, region) {
559564

560565
items.forEach((item) => {
561566
if (item.type === 'video') {
567+
normalizeOneInvidiousVideoAttributes(item)
562568
setPublishedTimestamp(item)
563569
}
564570
})
@@ -597,6 +603,7 @@ export async function getInvidiousSearchResults(query, page, searchSettings) {
597603

598604
results.forEach((item) => {
599605
if (item.type === 'video') {
606+
normalizeOneInvidiousVideoAttributes(item)
600607
setPublishedTimestamp(item)
601608
}
602609
})
@@ -862,6 +869,7 @@ export async function getHashtagInvidious(hashtag, page = 1) {
862869
}
863870
})
864871

872+
normalizeManyInvidiousVideosAttributes(response.results)
865873
setMultiplePublishedTimestamps(response.results)
866874

867875
return response.results
@@ -979,6 +987,28 @@ export function mapInvidiousLegacyFormat(format) {
979987
}
980988
}
981989

990+
/**
991+
* @param {{
992+
* authorId: string | null,
993+
* }[]} videos
994+
* @param {string|null} [fallbackAuthorId]
995+
*/
996+
function normalizeManyInvidiousVideosAttributes(videos, fallbackAuthorId = null) {
997+
const actualFallbackAuthorId = fallbackAuthorId === '' ? null : fallbackAuthorId
998+
999+
videos.forEach((v) => normalizeOneInvidiousVideoAttributes(v, actualFallbackAuthorId))
1000+
}
1001+
1002+
/**
1003+
* @param {{
1004+
* authorId: string | null,
1005+
* }} video
1006+
* @param {string|null} [fallbackAuthorId]
1007+
*/
1008+
function normalizeOneInvidiousVideoAttributes(video, fallbackAuthorId = null) {
1009+
if (video.authorId === '') video.authorId = fallbackAuthorId
1010+
}
1011+
9821012
/**
9831013
* @param {{
9841014
* liveNow: boolean,

0 commit comments

Comments
 (0)