問題描述
我正在 Discord.JS(它是 Node.JS 的庫)中創建一個機器人,我想向它添加一個音樂模塊.Discord.JS 可以在語音頻道中播放 .wav、.mp4 等格式的視頻.我想為用戶添加一種可能性,只需輸入視頻的 YouTube 網址即可播放.是否有可能通過 API 或任何其他方式從 YouTube 網址獲取視頻網址?
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?
推薦答案
您過去可以通過 youtube.com/get_video?video_id=...
輕松獲得它,但這就像5 多年前,現在我認為它使用了一些奇怪的流東西.
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.
我認為 Youtube 的官方 API 不允許您下載視頻或獲取 URL.此外,您可能應該查看 YouTube TOS
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
您不得下載任何內容,除非您看到 YouTube 在該內容的服務上顯示下載"或類似鏈接.
You shall not download any Content unless you see a "download" or similar link displayed by YouTube on the Service for that Content.
但無論如何,我知道的一種方法是 youtube-dl,但我是很確定它只適用于python.不過,網上似乎有一些節點包裝器(ex.)
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.)
我還找到了一個 node.js youtube 下載器,ytdl.上次更新是 9 天前,所以它應該可以在當前系統上正常工作.您應該可以使用 -o filename
或 --output filename
下載它,或 --print-url
直接獲取視頻網址.
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.
這篇關于如何從 youtube url 獲取視頻的直接 url?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!