PEAR have rich library to access web based resources easily…

<?php

$sv = new SVTube();
$sv->download(“D7cm-yu-CP0”, “phpsolutions.flv”)

?>

Class: SVTube.php
——————————

<?php

require_once ‘HTTP/Client.php’;
require_once ‘HTTP/Request.php’;

class SVTube {

var $req;
var $debug = false;
var $auth = false;

function download ($video_id, $video_filename) {
$url = “http://www.youtube.com/watch?v=”.$video_id;
$this->req =& new HTTP_Request($url);
$response = $this->req->sendRequest();

if (PEAR::isError($response)) {
echo $response->getMessage().”\n”;
} else {
$page = $this->req->getResponseBody();

preg_match(‘/\&t=([^”]*)”/si’, $page, $match);

$html=html_entity_decode(urldecode(str_replace(‘\x’, ‘%’, $match[1])),ENT_QUOTES, “UTF-8”);

$echo = explode(“&”, $html);

$url = “http://www.youtube.com/get_video?el=detailpage&t=”.$echo[0].”&fmt=5&asv=3&video_id=”.$video_id;

if ($this->debug)
return $url.”\n”;

$req =& new HTTP_Request($url,array (“allowRedirects”=>true, “maxRedirects”=> 99));
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->addHeader(“User-Agent”,”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”);
$response = $req->sendRequest();

$req->getResponseBody();

if (PEAR::isError($response)) {
//echo $response->getMessage().”\n”;
return “Error: Failed to open video file on YouTube\n”;
} else {
if ($o = fopen ($video_filename, “w”)) {
fwrite($o,$req->getResponseBody());
fclose ($o);
return “Download complete! File: “.$video_filename.”\n”;
} else {
return “Error: Failed to open video-file\n”;
}
}

}
}

}
?>

22 Responses to Download youtube videos using PEAR

  1. Anonymous says:

    Kudos for posting such a useful weblog. Your blog isn’t only informative but very artistic too. There tend to be very couple of those who can write not simple articles that creatively. Keep up the favorable writing !!

  2. Anonymous says:

    Each and every time I visit this great site there’s new stuff and improved for me to study on. Haha I’ve been in your source code many times to understand how you’re using things so we could wear them my site. Thanks! I will educate you about approaches to make money online and.

  3. Anonymous says:

    great share, great article, very usefull for me…thank you

  4. karen says:

    Really nice and impressive blog i found today.

  5. Anonymous says:

    What a lovely blog page. I’ll definitely be back. Please maintain writing!

  6. Curvature says:

    You wouldn’t believe it but I’ve wasted all day digging for some articles about this. You are a lifesaver, it was an beneficial read and has helped me out to no end. Cheers!

  7. sun says:

    I just now needed to brief review your site plus declare we truly appreciated looking at your site posting here. It turned out quite beneficial and that i as well reddit and the choice of write! Keep it up and also We will be in to study a lot more before long mate

  8. Anonymous says:

    Hi Guy, this good blogs, thanks

  9. Anonymous says:

    Sweet, that’s definitely what I was hunting for! You just spared me alot of looking around

  10. Anonymous says:

    Really need to subscribe to this blog, fantastic article. Think it is with bing.

  11. Anonymous says:

    I was rather pleased to come across this site.I wanted to thank you for this great study!! I most certainly enjoying every single tiny bit of it and I’ve you bookmarked to verify out new stuff you article.

  12. ray ban says:

    Many thanks this specific fascinating short article. I’ll seem for ones weblog on a regular basis today. I’m contemplating this subject given that years and you may have good infos. Hi coming from Malaysia

  13. Anonymous says:

    Fine internet site!

  14. Anonymous says:

    Good blog, where did you come up with the knowledge in this piece of content? Im glad I found it though, ill be checking back soon to see what other articles you have.

  15. Anonymous says:

    Thanks to you to get therefore exciting article. Great job!

  16. Anonymous says:

    This is often a great blog site which assists me to get additional data to the topic. I am bookmark it!

  17. Anonymous says:

    This is wonderful post, We are within impressed go through these individuals would have been a joy.

  18. Anonymous says:

    Hello there, When i identified your blog inside a brand new index of knowledge sites. My spouse and i do not discover how ones weblog turned up right up, will need to have got

  19. Anonymous says:

    Great blog! I genuinely love how it is easy on my eyes as well as the info are well written. I am wondering how I may be notified whenever a new post has been made. I have subscribed to your rss feed which need to do the trick! Have a nice day!

  20. Anonymous says:

    Great post!

  21. Anonymous says:

    There are numerous great thoughts below. I must modernize this website sometimes. I am going to originate from the begining now I believe.

  22. Boston Bruins says:

    Your web site arrived up in doing my analysis in addition to i’m troubled by what you’ve got ready on this subject material. I’m right now diversifying my personal search and so are unable to contribute more, nonetheless, I have added your blog and will be re-occurring to maintain up using virtually any forthcoming modifications. Basically appreciate it plus thank you for enabling my own thoughts.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.