有没有一个java API可以从youtube下载视频?

发布于 2024-10-28 04:01:55 字数 669 浏览 1 评论 0原文

我知道 YouTube Java API 不提供从 YouTube 下载视频的功能。但是,有没有办法使用 Java 下载给定浏览器 url 的 YouTube 视频并将其保存到文件中?我正在寻找类似的东西:

URL videoURL = getVideoURL();
// videoURL is input from user, as in http://www.youtube.com/watch?v=dfjghdjogdjgh
YoutubeVideo videoDownload = new YoutubeVideo(videoURL);
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(getOutFile()));
//getOutfile gets file provided by user
InputStream inStream = new BufferedInputStream(videoDownload.getInputStream());
byte[] buffer = new byte[4096];
int n;
while ((n = inStream.read(buffer)) != -1){
    outStream.write(buffer, 0, n);
}
outStream.close();
inStream.close();

I know that the YouTube Java API doesn't provide functionality for downloading a video from youtube. However, is there any way to download a youtube video given the browser url with Java and save to a file? I'm looking for something along these lines:

URL videoURL = getVideoURL();
// videoURL is input from user, as in http://www.youtube.com/watch?v=dfjghdjogdjgh
YoutubeVideo videoDownload = new YoutubeVideo(videoURL);
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(getOutFile()));
//getOutfile gets file provided by user
InputStream inStream = new BufferedInputStream(videoDownload.getInputStream());
byte[] buffer = new byte[4096];
int n;
while ((n = inStream.read(buffer)) != -1){
    outStream.write(buffer, 0, n);
}
outStream.close();
inStream.close();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文