-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Labels
bugSomething isn't workingSomething isn't working
Description
⨯ [TypeError: Cannot read properties of undefined (reading 'videoId')]
GET /api/youtube/video/subtitle?videoId=sFge0ToKxQc 500 in 1327ms
⨯ node_modules/.pnpm/[email protected]/node_modules/youtubei/dist/esm/youtube/BaseVideo/BaseVideoParser.js (24:1) @ BaseVideoParser.loadBaseVideo
⨯ Internal error: TypeError: Cannot read properties of undefined (reading 'videoId')
at BaseVideoParser.loadBaseVideo (./node_modules/.pnpm/[email protected]/node_modules/youtubei/dist/esm/youtube/BaseVideo/BaseVideoParser.js:33:44)
at BaseVideo.load (./node_modules/.pnpm/[email protected]/node_modules/youtubei/dist/esm/youtube/BaseVideo/BaseVideo.js:40:71)
at Video.load (./node_modules/.pnpm/[email protected]/node_modules/youtubei/dist/esm/youtube/Video/Video.js:76:31)
at Client.eval (./node_modules/.pnpm/[email protected]/node_modules/youtubei/dist/esm/youtube/Client/Client.js:192:99)
at step (./node_modules/.pnpm/[email protected]/node_modules/youtubei/dist/esm/youtube/Client/Client.js:55:23)
at Object.eval [as next] (./node_modules/.pnpm/[email protected]/node_modules/youtubei/dist/esm/youtube/Client/Client.js:36:53)
at fulfilled (./node_modules/.pnpm/[email protected]/node_modules/youtubei/dist/esm/youtube/Client/Client.js:27:58)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
22 | var videoInfo = BaseVideoParser.parseRawData(data);
23 | // Basic information
> 24 | target.id = videoInfo.videoDetails.videoId;
| ^
25 | target.title = videoInfo.videoDetails.title;
26 | target.uploadDate = videoInfo.dateText.simpleText;
27 | target.viewCount = +videoInfo.videoDetails.viewCount || null;
my code is:
import {Client} from "youtubei";
export async function GET(req: Request) {
const url = new URL(req.url);
const queryParams = new URLSearchParams(url.search);
const videoId = queryParams.get('videoId') || "";
const youtube = new Client();
const video = await youtube.getVideo(videoId)
const videoCaptions = video?.captions;
const languages = videoCaptions?.languages
if (!languages) {
return Response.json({code: 0, message: "success", data: ""});
}
const language = languages.find(l => l.code === "en" || l.isTranslatable);
if (!language) {
return Response.json({code: 0, message: "success", data: ""});
}
const captions = await language.get("en")
if (!captions) {
return Response.json({code: 0, message: "success", data: ""});
}
const subtitles = captions
.map((caption) => caption.text)
.filter((t) => t !== undefined && t !== null && t.trim().length > 0)
.join(" ");
return Response.json({code: 0, message: "success", data: subtitles});
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working