在YouTube上使用get_video下载视频 [英] Using get_video on YouTube to download a video
问题描述
我正在尝试获取任何YouTube视频的视频网址,如下所示:
I am trying to get the video URL of any YouTube video like this:
打开
http://youtube.com/get_video_info?video_id=VIDEOID
然后取 account_playback_token
令牌值,并打开此URL:
then take the account_playback_token
token value and open this URL:
http://www.youtube.com/get_video?video_id=VIDEOID&t=TOKEN&fmt=18&asv=2
这应该打开一个页面只是视频或开始下载视频。但没有任何事情发生,Safari的活动窗口会显示未找到,因此网址有问题。我想将它整合到一个iPad应用程序中,并且获取我在iPhone版本的应用程序中使用的视频网址的javascript方法不起作用,所以我需要另一个解决方案。
This should open a page with just the video or start a download of the video. But nothing happens, Safari's activity window says 'Not found', so there is something wrong with the URL. I want to integrate this into a iPad app, and the javascript method to get the video URL I use in the iPhone version of the app isn't working, so I need another solution.
YouTube更改所有时间,我认为网址刚刚过时。请帮助:)
YouTube changes all the time, and I think the URL is just outdated. Please help :)
编辑:似乎get_video方法不再工作了。我真的很感激任何人可以告诉我另一种方式来找到视频网址。
It seems like the get_video method doesn't work anymore. I'd really appreciate if anybody could tell me another way to find the video URL.
谢谢,我真的需要帮助。
Thank you, I really need help.
推荐答案
对不起,这是不可能的。他们将令牌限制在获得它的IP上。
Sorry, that is not possible anymore. They limit the token to the IP that got it.
使用 get_headers()
函数,它为您提供了一个包含视频链接的数组。我不知道任何关于 ios
的信息,所以希望你可以自己重写这个PHP代码。
Here's a workaround by using the get_headers()
function, which gives you an array with the link to the video. I don't know anything about ios
, so hopefully you can rewrite this PHP code yourself.
<?php
if(empty($_GET['id'])) {
echo "No id found!";
}
else {
function url_exists($url) {
if(file_get_contents($url, FALSE, NULL, 0, 0) === false) return false;
return true;
}
$id = $_GET['id'];
$page = @file_get_contents('http://www.youtube.com/get_video_info?&video_id='.$id);
preg_match('/token=(.*?)&thumbnail_url=/', $page, $token);
$token = urldecode($token[1]);
$get = $title->video_details;
$url_array = array ("http://youtube.com/get_video?video_id=".$id."&t=".$token,
"http://youtube.com/get_video?video_id=".$id."&t=".$token."&fmt=18");
if(url_exists($url_array[1]) === true) {
$file = get_headers($url_array[1]);
}
elseif(url_exists($url_array[0]) === true) {
$file = get_headers($url_array[0]);
}
$url = trim($file[19],"Location: ");
echo '<a href="'.$url.'">Download video</a>';
}
?>
这篇关于在YouTube上使用get_video下载视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!