Search code examples
node.jsdiscordytdl

How do I get a YouTube video title from a YouTube URL in Node.Js


I need to get a video title from a YouTube URL, I have no clue how to do it. I have asked on two discord support servers. I have got this code so far (i am also using YTDL-CORE)

const TEST = ytdl.getInfo('https://www.youtube.com/watch?v=YQHsXMglC9A', function (err, info) {
    console.log(info.videoDetails.title) // "Adele - Hello"
});


Solution

  • The promising is not going to the desired function hence not printing the title. You should do something like this and voila.

    ytdl.getInfo('https://www.youtube.com/watch?v=YQHsXMglC9A').then(info => {
        console.log(info.videoDetails.title);
    })
    

    Adele - Hello