views:

317

answers:

1

i m using phptube class for downloading you tube video.

from this site

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&amp;t=

here $t is null , how do get $ticket from youtube url

+1  A: 

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!

mattbasta
Thank you sir, second error has been resoved but first error stiil appears, please go through that site from where i download the code, you may get some idea.
diEcho
diEcho
my input is youtube video url
diEcho
Just looked up how YT passes this stuff: they have since changed their system since that code was published. Previously, they relied on redirects (which are easy to sniff out). Now, they don't. You'll likely need to figure out how the video id and token are passed to the SWF player in order to grab these things out. Sorry for the bad news.
mattbasta
i succeed to download YT video at local system by above code, but on server there is blank flv file is downloading...what should i do with server??how to know that pear is installed or not on server??
diEcho