I have ytdl-core downloaded and im using it with discord.js. I have a mand that plays a YouTube video's audio into voice chat. Does anybody know a way I can get JUST the string of the video title from a link, or a simple way to get the title? Even easier would be just a way to get the title of the video from the link somehow. Any help is appreciated! Thanks!
I have ytdl-core downloaded and im using it with discord.js. I have a mand that plays a YouTube video's audio into voice chat. Does anybody know a way I can get JUST the string of the video title from a link, or a simple way to get the title? Even easier would be just a way to get the title of the video from the link somehow. Any help is appreciated! Thanks!
Share Improve this question asked Aug 7, 2016 at 3:10 NicNic 761 gold badge1 silver badge7 bronze badges4 Answers
Reset to default 5what you are looking for is getInfo()
https://github./fent/node-ytdl-core#ytdlgetinfourl-options-callbackerr-info
getInfo('https://www.youtube./watch?v=YQHsXMglC9A', function(err, info) {
console.log(info.title) // "Adele - Hello"
});
While you're streaming the audio through Node.JS pipes to a WebSocket
.
You could use the already fetched information to make it efficient!
var stream = YTDL('https://youtu.be/H7NuU-dDRLU');
/* Spit-out information when recieved */
stream.on('info', (info) => {
console.log(info.title); // Tobu - Roots
console.log(info.video_id); // H7NuU-dDRLU
});
Note: If just needed to fetch information then use
YTDL.getInfo
instead.
You can use the function below, it works perfectly for me:
function getTitleVideo (videoUrl){
return new Promise ((resolve, reject) => {
ytdl.getBasicInfo (videoUrl, (err, info) => {
resolve (info.title)
})
})
}
Use getInfo()
as info.title
is no more valid due to some changes in ytdl-core
.
Example:
getInfo('https://www.youtube./watch?v=YQHsXMglC9A', (info) => {
// console.log(info.title) Alert! this is Wrong
console.log(info.videoDetails.title) // "Adele - Hello"
});