How to get direct url of video from youtube url? [closed]

血红的双手。 提交于 2019-12-24 19:23:41

问题


I'm creating a bot in Discord.JS (it's a library for Node.JS) and I would like to add a music module to it. Discord.JS can play videos in formats like .wav, .mp4 etc. in voice channels. I would like to add a possibility for users to just type a YouTube url of a video to play it. Is there any possibility to get a video's url from an YouTube url by an API or any other way?


回答1:


You used to be able to get it pretty easily with youtube.com/get_video?video_id=... but that was like 5+ years ago, now I think it uses some weird stream thing.

I don't think Youtube's official API lets you download videos or get a URL. Also, you should probably take a look at section 5B of the YouTube TOS

You shall not download any Content unless you see a “download” or similar link displayed by YouTube on the Service for that Content.

But anyway, one method I know is youtube-dl, but I'm pretty sure it's only for python. There seem to be a few node wrappers online though (ex.)

I've also found a node.js youtube downloader, ytdl. Last update was 9 days ago so it should probably be working fine with the current system. You should be able to use -o filename or --output filename to download it, or --print-url to get a direct video url.




回答2:


You could use FFMPEG to download video and then play that file



来源:https://stackoverflow.com/questions/45652696/how-to-get-direct-url-of-video-from-youtube-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!