从ytdl-core获取视频标题

时间:2022-11-27 16:46:25

I have ytdl-core downloaded and im using it with discord.js. I have a command 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!

我已经下载了ytdl-core,并将其与discord.js一起使用。我有一个命令可以将YouTube视频的音频播放到语音聊天中。有没有人知道我可以通过链接得到视频标题的字符串,或者获取标题的简单方法?更简单的方法就是以某种方式从链接中获取视频标题。任何帮助表示赞赏!谢谢!

1 个解决方案

#1


1  

what you are looking for is getInfo()

你要找的是getInfo()

https://github.com/fent/node-ytdl-core#ytdlgetinfourl-options-callbackerr-info

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

#1


1  

what you are looking for is getInfo()

你要找的是getInfo()

https://github.com/fent/node-ytdl-core#ytdlgetinfourl-options-callbackerr-info

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