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
Leave a Reply
You must be logged in to post a comment.
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 !!
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.
great share, great article, very usefull for me…thank you
Really nice and impressive blog i found today.
What a lovely blog page. I’ll definitely be back. Please maintain writing!
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!
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
Hi Guy, this good blogs, thanks
Sweet, that’s definitely what I was hunting for! You just spared me alot of looking around
Really need to subscribe to this blog, fantastic article. Think it is with bing.
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.
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
Fine internet site!
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.
Thanks to you to get therefore exciting article. Great job!
This is often a great blog site which assists me to get additional data to the topic. I am bookmark it!
This is wonderful post, We are within impressed go through these individuals would have been a joy.
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
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!
Great post!
There are numerous great thoughts below. I must modernize this website sometimes. I am going to originate from the begining now I believe.
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.