最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get video title from ytdl-core - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

4 Answers 4

Reset to default 5

what 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"
});

发布评论

评论列表(0)

  1. 暂无评论