Reputation: 54060
i m using phptube class for downloading you tube video.
In code i paste youtube url on a input box but there is errors below.
Warning: file_get_contents(http://www.youtube.com/get_video?video_id=&t=)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.0 404 Not Found
and
Warning: file_put_contents(./flvs/3Hx9VsqMUug.flv) [function.file-put-contents]:
failed to open stream: No such file or directory in E:\xampp\htdocs\vdo\utube
\functions.php on line 19
path:./flvs/3Hx9VsqMUug.flv
please tell me where is problem???
UPDATE:
here is main code
$url = "http://www.youtube.com/watch?v=".$video_id;
//where $video_id=nlZJ7RsyC0g
$this->req =& new HTTP_Request($url);
//echo "<pre>";
//print_r($this->req);
//echo "</pre>";
//die;
$response = $this->req->sendRequest();
//echo $response; die;
if (PEAR::isError($response)) {
//echo "inside if";
$response->getMessage()."\n";
} else {
//echo "inside else";
$page = $this->req->getResponseBody();
//print_r($page);
//var_dump($page);
//die;
preg_match("/video_id=(\w*)/",$page,$mv);
$v_id = $mv[1];
preg_match("/&t=([\w]*)&/",$page,$tickets);
$ticket = $tickets[1];
$curl = "";
$curl .= $v_id;
$curl .= "&t=";
$curl .= $ticket;
//echo $curl;
$url = "http://www.youtube.com/get_video?video_id=".$curl;
echo $url;
die;
if ($this->debug)
return $url;
output($url) is
http://www.youtube.com/get_video?video_id=nlZJ7RsyC0g&t=
here $t
is null , how do get $ticke
t from youtube url
Upvotes: 1
Views: 1829
Reputation: 10560
I know that this post is damn old. But since this page is in the first five results for a Google search for "PHP class to download Youtube videos" - and therefore others might come across this thread, I'd like to refer to my own (open source) PHP class which is fully functional (at the time of writing this) and - on top - has an additional feature to not only download videos from YT, but also to convert them to mp3 audio files.
You can find it at my GitHub: https://github.com/eyecatchup/php-yt_downloader I hope this helps someone.
Upvotes: 0
Reputation: 6587
Did you try a different class - try this one - works a treat for me and it has all you could possibly need to get the video and all associated data: PHP Youtube Class
Upvotes: 1
Reputation: 13709
Your second error is because you don't have a directory called /flvs/
. Create that in the same directory as your executing script and you'll be golden.
As for your first error, it sounds like YouTube could be blocking your server. Try setting a user agent before making the request:
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
(I found that snippet online in lieu of taking the time to write my own. Just saying.)
Also, it doesn't look like you're passing any parameters (?video_id=&t=
). Either the phptube plugin you're using is jacked or you're not passing in correct values. What is your input?
Hope this helps!
Upvotes: 1