I'm trying to build a youtube video downloader using node, express and ytdl-core, but I'm getting the error "Cannot read property 'url' of undefined". The video is downloaded, but the file is corrupted, before adding the render, the download was ok
This is my js:
app.get("/", function (req, res) {
const { url } = req.query;
ytdl.getInfo(url).then((info) => {
let name = info.videoDetails.title;
let thumbnail = info.videoDetails.thumbnail.thumbnails[4].url;
res.header("Content-Disposition", `attachment; filename="${name}.mp4"`);
res.render("index.ejs", { name, thumbnail });
return ytdl(url).pipe(res);
});
});
app.listen(3000);
Thanks for the help!