如何从 youtube url 获取视频的直接 url?

时间:2023-02-10
本文介绍了如何从 youtube url 获取视频的直接 url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 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模板网!

上一篇:`TypeError: member.hasPermission() is not a function`在disco 下一篇:Discord JS//尝试通过对消息做出反应来添加角色

相关文章

最新文章