如何使用java获取Youtube下载链接? [英] How to get the Youtube download link using java?

查看:39
本文介绍了如何使用java获取Youtube下载链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道通过 VGet 可以轻松下载 youtube 视频.但是,我只想获取下载链接以在我的应用程序的其余部分 (Java Swing) 中使用它.可以使用 VGet 来完成吗?

I know that downloading a youtube video is made easy by VGet. But, i just want to get the download link to use it in rest of my application (Java Swing) . Can it be done using VGet?

有人可以帮我吗?

谢谢.

推荐答案

我找到的最简单的解决方案如下,YouTube 视频的 HTML 页面中包含文件的 URL.

The easiest solution I found is as follows, Contained in the HTML page of the YouTube video is the URL of the file.

在该页面上搜索类似于 'url=https%3A%2F%2Fr12---sn-5hne6nse.googlevideo.com%2' 的代码

Search that page for a code looking something like 'url=https%3A%2F%2Fr12---sn-5hne6nse.googlevideo.com%2'

这不是完整的 URL,但它指向特定分辨率的一个条目.从最高可用分辨率开始,对每个可用分辨率重复此代码.我做了一些测试,发现让文件播放所需的最小 URL 如下

This is not the complete URL but it points to one entry of a certain resolution. This code is repeated for every resolution available starting with the highest available. I did some testing and found the minimum URL required to get the file to play as follows

所以如果你想要 720p 版本,

so if you want the 720p version then,

我发现 'quality=hd720\' 和 'ratebypass%3Dyes' 之间包含的代码如果粘贴到浏览器中会播放所需的文件,因此如果您随后使用,

I found the code contained between 'quality=hd720\' and 'ratebypass%3Dyes' if pasted into a browser plays the required file so if you then use,

String result = str.substring(str.indexOf("quality=hd720"), str.indexOf("ratebypass%3Dyes"));

String result = str.substring(str.indexOf("quality=hd720"), str.indexOf("ratebypass%3Dyes"));

假设有 720 可用将拉出播放文件所需的 URL.

assuming there is a 720 available will pull out the URL needed to play the file.

使用 Uri.decode(url) 解码 URL 以删除那些 %codes

Decode the URL using Uri.decode(url) to remove those %codes

嘿,快,Java 中用作 URL 的剩余部分将下载文件.

and hey presto, whats left used as a URL in Java will download the file.

这篇关于如何使用java获取Youtube下载链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆