我如何获得完整的mp4 url来播放视频从它的实际位置在我的应用程序中使用一些其他来源,除了Youtube。gdata/youtube API已被弃用,所以我有麻烦。任何帮助都将不胜感激。谢谢。
我做了一个非常简单的API: https://gist.github.com/egyjs/9e60f1ae3168c38cc0f0054c15cd6a83
为例:YouTube视频链接:https://www.youtube.com/watch?v=**YGCLs9Bt_KY**
现在获得直接链接
您需要调用API,像这样(将example.com更改为您的站点):
https://example.com/?url=https://www.youtube.com/watch?v=YGCLs9Bt_KY
的回报:
[
{
"url": "https://r10---sn-aigllnlr.googlevideo.com/videoplayback?key=yt6&signature=81D86D3BC3D34D8A3B865464BE7BC54F34C1B0BC.7316033C2DD2F65E4D345CFA890257B63D7FE2A2&mt=1522999783&expire=1523021537&sparams=dur%2Cei%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&requiressl=yes&ei=gSLHWvuxDMOUVYaTqYgB&dur=244.204&pl=22&itag=22&ip=185.27.134.50&lmt=1522960451860848&id=o-AAoaDzyDCVXS404wfqZoCIdolGU-NM3-4yDxC0t868iL&ratebypass=yes&ms=au%2Conr&fvip=2&source=youtube&mv=m&ipbits=0&mm=31%2C26&mn=sn-aigllnlr%2Csn-5hne6nsy&mime=video%2Fmp4&c=WEB&initcwndbps=710000",
"quality": "hd720",
"itag": "22",
"type": "video/mp4; codecs="avc1.64001F, mp4a.40.2""
},
{
"url": "https://r10---sn-aigllnlr.googlevideo.com/videoplayback?key=yt6&mt=1522999783&gir=yes&expire=1523021537&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&itag=43&ratebypass=yes&fvip=2&ipbits=0&mime=video%2Fwebm&initcwndbps=710000&signature=71DC48B9BF4B2E3ED46FE0A4CD36FE027DACF31E.4624B7B4BCB947336CEB029E9958B136F79759EB&clen=24203231&requiressl=yes&dur=0.000&pl=22&ip=185.27.134.50&lmt=1522961642553275&ei=gSLHWvuxDMOUVYaTqYgB&ms=au%2Conr&source=youtube&mv=m&id=o-AAoaDzyDCVXS404wfqZoCIdolGU-NM3-4yDxC0t868iL&mm=31%2C26&mn=sn-aigllnlr%2Csn-5hne6nsy&c=WEB",
"quality": "medium",
"itag": "43",
"type": "video/webm; codecs="vp8.0, vorbis""
},
{
"url": "https://r10---sn-aigllnlr.googlevideo.com/videoplayback?key=yt6&mt=1522999783&gir=yes&expire=1523021537&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&itag=18&ratebypass=yes&fvip=2&ipbits=0&mime=video%2Fmp4&initcwndbps=710000&signature=C83DE33E3DC80981A65DB3FE4E6B3A48BF7500E4.361D0EE6210B30D3D3A80F43228DEF1BD20691A4&clen=15954979&requiressl=yes&dur=244.204&pl=22&ip=185.27.134.50&lmt=1522960340235683&ei=gSLHWvuxDMOUVYaTqYgB&ms=au%2Conr&source=youtube&mv=m&id=o-AAoaDzyDCVXS404wfqZoCIdolGU-NM3-4yDxC0t868iL&mm=31%2C26&mn=sn-aigllnlr%2Csn-5hne6nsy&c=WEB",
"quality": "medium",
"itag": "18",
"type": "video/mp4; codecs="avc1.42001E, mp4a.40.2""
},
{
"url": "https://r10---sn-aigllnlr.googlevideo.com/videoplayback?key=yt6&mt=1522999783&gir=yes&expire=1523021537&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&itag=36&fvip=2&ipbits=0&mime=video%2F3gpp&initcwndbps=710000&signature=3E993D911492DA039A16BB26182ACDC6C6A04FCC.BFB9728C71CD03970B0F15AFD51A7355F9D3F899&clen=6759799&requiressl=yes&dur=244.273&pl=22&ip=185.27.134.50&lmt=1522957367267598&ei=gSLHWvuxDMOUVYaTqYgB&ms=au%2Conr&source=youtube&mv=m&id=o-AAoaDzyDCVXS404wfqZoCIdolGU-NM3-4yDxC0t868iL&mm=31%2C26&mn=sn-aigllnlr%2Csn-5hne6nsy&c=WEB",
"quality": "small",
"itag": "36",
"type": "video/3gpp; codecs="mp4v.20.3, mp4a.40.2""
},
{
"url": "https://r10---sn-aigllnlr.googlevideo.com/videoplayback?key=yt6&mt=1522999783&gir=yes&expire=1523021537&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&itag=17&fvip=2&ipbits=0&mime=video%2F3gpp&initcwndbps=710000&signature=810D13A2C507A4EA220E6DA895B39B237FA22DAF.898D020851087CF3C10BC6E3ED7360736A239904&clen=2443931&requiressl=yes&dur=244.273&pl=22&ip=185.27.134.50&lmt=1522957365473654&ei=gSLHWvuxDMOUVYaTqYgB&ms=au%2Conr&source=youtube&mv=m&id=o-AAoaDzyDCVXS404wfqZoCIdolGU-NM3-4yDxC0t868iL&mm=31%2C26&mn=sn-aigllnlr%2Csn-5hne6nsy&c=WEB",
"quality": "small",
"itag": "17",
"type": "video/3gpp; codecs="mp4v.20.3, mp4a.40.2""
}
]
更新:
查看源代码:要点:https://gist.github.com/egyjs/9e60f1ae3168c38cc0f0054c15cd6a83
对不起,您不能在youtube api v3中这样做。你必须使用YouTube的url它不是api,但在这里你可以得到所有与此相关的视频。看到http://www.youtube.com/get_video_info?& video_id ="。my_id。美元,asv = 3, el = detailpage& hl = en_US
或者你可以做得到所有的视频下载链接,即使它是私人的或不允许你的国家1 .进入youtube视频链接https://www.youtube.com/watch?v=9mdJV5-eias
2:查看该页的源代码
3rd: 188或187行,在那里你可以找到源Javascript代码,其中mp4格式的视频位置也是可用的。
你可以通过simplehtmldom和一些php函数来实现第二个想法。第一个可以通过curl得到它很简单,但用php有点难。谢谢你,希望这对你有帮助。
对于本地Java/Android,这里是我如何实现这一点,功劳要归功于@abdo-el-zahaby我将他的php脚本转换为~等效的Java代码,它使用okhttp客户端获取url
final String videoInfoUrl = "http://www.youtube.com/get_video_info?video_id=some_video_id&el=embedded&ps=default&eurl=&gl=US&hl=en";
Request request = new Request.Builder()
.cacheControl(CacheControl.FORCE_NETWORK)
.url(videoInfoUrl)
.build();
final Response response = okHttpClient.newCall(request).execute();
InputStream inputStream = response.body().byteStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
final StringBuilder contentBuilder = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
contentBuilder.append(line);
}
final String streamKey = "url_encoded_fmt_stream_map";
final Map<String, String> map = new HashMap<>();
final String content = contentBuilder.toString();
String[] ampSplit = content.split("&");
for (String s : ampSplit) {
printDivider();
final String[] equalsPlit = s.split("=");
if (equalsPlit.length >= 2) {
String key;
String value;
key = equalsPlit[0];
value = equalsPlit[1];
map.put(key, value);
}
printDivider();
}
int count = 0;
if (map.containsKey(streamKey)) {
String[] streams = map.get(streamKey).split(",");
for (String stream : streams) {
String[] streamSplit = stream.split("&");
for (String s : streamSplit) {
printDivider();
final String urlDecoded = URLDecoder.decode(s, "UTF-8");
String[] details = urlDecoded.split(",");
for (String detail : details) {
System.out.println("Detail " + URLDecoder.decode(detail, "UTF-8"));
final String urlContent= URLDecoder.decode(detail, "UTF-8");
final String url = urlContent.substring(urlContent.indexOf("http"), urlContent.indexOf(";"));
mp4Url.put(Integer.toString(count++), url);
}
}
printDivider();
}
}
这是我用来下载和存储在sd卡/内存的代码
Request request = new Request.Builder()
.cacheControl(CacheControl.FORCE_NETWORK)
.url(url)
.build();
final Response response = okHttpClient.newCall(request).execute();
InputStream inputStream = response.body().byteStream();
final File newFile = new File(location);
boolean created = newFile.createNewFile();
System.out.println(location + " new file created: " + created);
byte[] buff = new byte[4096];
long downloaded = 0;
long target = response.body().contentLength();
System.out.println("File size is: " + Long.toString(target));
OutputStream outStream = new FileOutputStream(newFile);
while (true) {
int read = inputStream.read(buff);
if (read == -1) {
break;
}
outStream.write(buff, 0, read);
//write buff
downloaded += read;
}
System.out.println("Target: " + target +", Downloaded: " + downloaded);
outStream.flush();
这很简单在MSEDGE中,获取Network中的请求面板,然后键入:
videoplayback
你会得到一个视频回放列表,去红色的前三个,获取第一个,然后复制URL,转到它,然后复制并粘贴出现的原始URL,瞧!例:https://www.youtube.com/watch?v=kyCJ17oq6kI被翻译成https://rr5---sn-4g5lznek.googlevideo.com/videoplayback?expire=1681055644&ei=PIsyZLKiDf2pxN8Pycma6Ac&ip=197.133.92.36&id=o-AG5C0lZuVpm9QTlY3-bdsnaxXFDmYWZNMfSnHEevldCX&itag=244&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C271%2C278%2C313%2C394%2C395%2C396%2C397%2C398%2C399%2C400%2C401&source=youtube&requiressl=yes&spc=99c5CQGgativKiOByrtN4P3IwKXbF2U&vprv=1&mime=video%2Fwebm&ns=GZQIER86iMv1E06YUDtOUIUM&gir=yes&clen=51126864,大调的= 930.629及以前= 1661735478649394,keepalive = yes& fexp = 24007246和c = WEB_EMBEDDED_PLAYER& txp = 5537434, n = 60 ejg2vtl7kl_a& sparams = % 2到期cei % 2 cip % 2 cid % 2 caitags % 2 csource % 2 crequiressl % 2中海壳牌% 2 cvprv % 2 cmime % 2 cns % 2 cgir % 2 cclen % 2 cdur % 2 clmt&团体= AOq0QJ8wRQIhAKOA0iAqWrySUp9NpkpcxJNJQ6C1_BWfa6b91zStEu5TAiA80wiRQvGJFEd-4iuq4fjM5r7SAc1zPjr4xv6PweEgxw % 3 d % 3 d&规律= yes&尼共= pDl8mDxKkx62PK2k&简历= 1.20230402.00.00&范围= 0 - 245662,rn = 1, rbuf = 0,锅= MmQ1aC1VTvz2 c242&pGTVQZjSBWLyWnbiGJ0bOAtQgoIovIYrGI3nBfAVO60KmMbRKcRxq5ySqI9TAJ4rqBnfcuoXzj7CAgJAA24AmShxWJhrSkAoI0LrSFPC_N6FCyu6xkeOf38wpoFXa& altitags = 243%; redirect_counter = 1, cm2rm = sn-8vq54voxxb-j5pd7d& req_id = 9 c5d1ec279bcda59& cms_redirect = yes& cmsv = e& mh = Yy&毫米= 29,mn = sn-4g5lznek&女士= rdu&太= 1681033985,mv = m&本= 5,pl = 22, lsparams = mh,毫米,mn, ms, mv,本,pl& lsig = AG3C_xAwRQIgcOPSyxayGZHivxtPhZzhmckywIeotUdp0Ny6sepZS-4CIQD52bhTS6Xu_GOWGg_GCIIl2ZcXXaQpy-mMMzhZaB2Mbg % 3 d % 3 d .
。
我不知道它是如何工作的,但检查https://podsync.net/。
当你输入一个youtube播放列表链接时,它会做一些神奇的事情,并生成一个mp4链接供播客捕获器使用。检查返回的xml文件,您将看到播放列表中每个视频的行如下:
<enclosure url="http://podsync.net/download/[random-letters]/[video-id].mp4" length="x" type="video/mp4"></enclosure>
根据我的经验,无论你使用什么视频id,这个URL都有效。