From 4e247a46aefaf0a6ba931f27053065cc8d266fe5 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 11 Nov 2025 21:54:48 +0800 Subject: [PATCH] fix(route/youtube): ensure youtubei is not invoked when using google api (#20469) --- lib/routes/youtube/api/google.ts | 12 ++++++------ lib/routes/youtube/api/youtubei.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/routes/youtube/api/google.ts b/lib/routes/youtube/api/google.ts index 4e422b826..82f718fae 100644 --- a/lib/routes/youtube/api/google.ts +++ b/lib/routes/youtube/api/google.ts @@ -145,7 +145,7 @@ export const getDataByUsername = async ({ username, embed, filterShorts, isJsonF }; }; -export const getDataByChannelId = async ({ channelId, embed, filterShorts }: { channelId: string; embed: boolean; filterShorts: boolean }): Promise => { +export const getDataByChannelId = async ({ channelId, embed, filterShorts, isJsonFeed }: { channelId: string; embed: boolean; filterShorts: boolean; isJsonFeed: boolean }): Promise => { // Get original uploads playlist ID if needed const originalPlaylistId = filterShorts ? null : (await utils.getChannelWithId(channelId, 'contentDetails', cache)).data.items[0].contentDetails.relatedPlaylists.uploads; @@ -155,7 +155,7 @@ export const getDataByChannelId = async ({ channelId, embed, filterShorts }: { c const data = (await utils.getPlaylistItems(playlistId, 'snippet', cache)).data.items; const videoIds = data.map((item) => item.snippet.resourceId.videoId); const videoDetails = await utils.getVideos(videoIds.join(','), 'contentDetails', cache); - const subtitlesMap = await getSrtAttachmentBatch(videoIds); + const subtitlesMap = isJsonFeed ? await getSrtAttachmentBatch(videoIds) : {}; return { title: `${data[0].snippet.channelTitle} - YouTube`, @@ -168,7 +168,7 @@ export const getDataByChannelId = async ({ channelId, embed, filterShorts }: { c const videoId = snippet.resourceId.videoId; const img = utils.getThumbnail(snippet.thumbnails); const detail = videoDetails?.data.items.find((d) => d.id === videoId); - const srtAttachments = subtitlesMap[videoId] || []; + const srtAttachments = subtitlesMap ? subtitlesMap[videoId] || [] : []; return { title: snippet.title, @@ -190,13 +190,13 @@ export const getDataByChannelId = async ({ channelId, embed, filterShorts }: { c }; }; -export const getDataByPlaylistId = async ({ playlistId, embed }: { playlistId: string; embed: boolean }): Promise => { +export const getDataByPlaylistId = async ({ playlistId, embed, isJsonFeed }: { playlistId: string; embed: boolean; isJsonFeed: boolean }): Promise => { const playlistTitle = (await utils.getPlaylist(playlistId, 'snippet', cache)).data.items[0].snippet.title; const data = (await utils.getPlaylistItems(playlistId, 'snippet', cache)).data.items.filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video'); const videoIds = data.map((item) => item.snippet.resourceId.videoId); const videoDetails = await utils.getVideos(videoIds.join(','), 'contentDetails', cache); - const subtitlesMap = await getSrtAttachmentBatch(videoIds); + const subtitlesMap = isJsonFeed ? await getSrtAttachmentBatch(videoIds) : {}; return { title: `${playlistTitle} by ${data[0].snippet.channelTitle} - YouTube`, @@ -207,7 +207,7 @@ export const getDataByPlaylistId = async ({ playlistId, embed }: { playlistId: s const videoId = snippet.resourceId.videoId; const img = utils.getThumbnail(snippet.thumbnails); const detail = videoDetails?.data.items.find((d) => d.id === videoId); - const srtAttachments = subtitlesMap[videoId] || []; + const srtAttachments = subtitlesMap ? subtitlesMap[videoId] || [] : []; return { title: snippet.title, diff --git a/lib/routes/youtube/api/youtubei.ts b/lib/routes/youtube/api/youtubei.ts index 98d57e670..ed2b0d4e9 100644 --- a/lib/routes/youtube/api/youtubei.ts +++ b/lib/routes/youtube/api/youtubei.ts @@ -68,7 +68,7 @@ export const getDataByChannelId = async ({ channelId, embed, isJsonFeed }: { cha }; }; -export const getDataByPlaylistId = async ({ playlistId, embed }: { playlistId: string; embed: boolean }): Promise => { +export const getDataByPlaylistId = async ({ playlistId, embed }: { playlistId: string; embed: boolean; isJsonFeed: boolean }): Promise => { const innertube = await innertubePromise; const playlist = await innertube.getPlaylist(playlistId); const videos = await playlist.videos;