feat(route/youtube): only get subtitle for jsonfeed (#20375)
This commit is contained in:
parent
e1fe935494
commit
1cc197a104
|
|
@ -54,7 +54,7 @@ if (config.youtube && config.youtube.clientId && config.youtube.clientSecret &&
|
|||
|
||||
export { youtubeOAuth2Client, exec };
|
||||
|
||||
export const getDataByUsername = async ({ username, embed, filterShorts }: { username: string; embed: boolean; filterShorts: boolean }): Promise<Data> => {
|
||||
export const getDataByUsername = async ({ username, embed, filterShorts, isJsonFeed }: { username: string; embed: boolean; filterShorts: boolean; isJsonFeed: boolean }): Promise<Data> => {
|
||||
let userHandleData;
|
||||
if (username.startsWith('@')) {
|
||||
userHandleData = await cache.tryGet(`youtube:handle:${username}`, async () => {
|
||||
|
|
@ -109,7 +109,7 @@ export const getDataByUsername = async ({ username, embed, filterShorts }: { use
|
|||
}
|
||||
const videoIds = playlistItems.data.items.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: `${userHandleData?.channelName || username} - YouTube`,
|
||||
|
|
@ -123,7 +123,7 @@ export const getDataByUsername = async ({ username, embed, filterShorts }: { use
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -14,16 +14,16 @@ export const getChannelIdByUsername = (username: string) =>
|
|||
return navigationEndpoint.payload.browseId;
|
||||
});
|
||||
|
||||
export const getDataByUsername = async ({ username, embed, filterShorts }: { username: string; embed: boolean; filterShorts: boolean }): Promise<Data> => {
|
||||
export const getDataByUsername = async ({ username, embed, filterShorts, isJsonFeed }: { username: string; embed: boolean; filterShorts: boolean; isJsonFeed: boolean }): Promise<Data> => {
|
||||
const channelId = (await getChannelIdByUsername(username)) as string;
|
||||
return getDataByChannelId({ channelId, embed, filterShorts });
|
||||
return getDataByChannelId({ channelId, embed, filterShorts, isJsonFeed });
|
||||
};
|
||||
|
||||
export const getDataByChannelId = async ({ channelId, embed }: { channelId: string; embed: boolean; filterShorts: boolean }): Promise<Data> => {
|
||||
export const getDataByChannelId = async ({ channelId, embed, isJsonFeed }: { channelId: string; embed: boolean; filterShorts: boolean; isJsonFeed: boolean }): Promise<Data> => {
|
||||
const innertube = await innertubePromise;
|
||||
const channel = await innertube.getChannel(channelId);
|
||||
const videos = await channel.getVideos();
|
||||
const videoSubtitles = await getSrtAttachmentBatch(videos.videos.filter((video) => 'video_id' in video).map((video) => video.video_id));
|
||||
const videoSubtitles = isJsonFeed ? await getSrtAttachmentBatch(videos.videos.filter((video) => 'video_id' in video).map((video) => video.video_id)) : {};
|
||||
|
||||
return {
|
||||
title: `${channel.metadata.title || channelId} - YouTube`,
|
||||
|
|
@ -35,7 +35,7 @@ export const getDataByChannelId = async ({ channelId, embed }: { channelId: stri
|
|||
videos.videos
|
||||
.filter((video) => 'video_id' in video)
|
||||
.map((video) => {
|
||||
const srtAttachments = videoSubtitles[video.video_id] || [];
|
||||
const srtAttachments = isJsonFeed ? videoSubtitles[video.video_id] || [] : [];
|
||||
const img = 'best_thumbnail' in video ? video.best_thumbnail?.url : 'thumbnails' in video ? video.thumbnails?.[0]?.url : undefined;
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -57,10 +57,12 @@ async function handler(ctx) {
|
|||
const filterShortsStr = params.get('filterShorts');
|
||||
const filterShorts = filterShortsStr === null || filterShortsStr === '' || filterShortsStr === 'true';
|
||||
|
||||
const isJsonFeed = ctx.req.query('format') === 'json';
|
||||
|
||||
const data = await callApi({
|
||||
googleApi: getDataByUsernameGoogle,
|
||||
youtubeiApi: getDataByUsernameYoutubei,
|
||||
params: { username, embed, filterShorts },
|
||||
params: { username, embed, filterShorts, isJsonFeed },
|
||||
});
|
||||
|
||||
return data;
|
||||
|
|
|
|||
Loading…
Reference in New Issue