Thursday 29th May 2008
by Sajith M.R
If you want to get the FLV file of any youtube video url using php code, here is the solution.
If you are a PHP Programmer and if you are working with any video website, and if you need to grab videos (FLV files) from youtube and to put it yourown site (not object embedding) , Download the Full Source Code given at the end of this article (ZIP)
I used this php code for the Youtube video download tool http://www.googleneedle.com
Here function getPatternFromUrl is nothing but, get the exact pattern of a particular video from any youtube video url format.
In the above case , it returns pzmP4UvZRa4
The function is below
function getPatternFromUrl($url)
{
$url = $url.'&';
$pattern = '/v=(.+?)&+/';
preg_match($pattern, $url, $matches);
return ($matches[1]);
}
GetFlvFromYoutube is the main function here, which download the flv file from youtube pattern and saves to your local machine.
The function is below:
function GrabFlvFromYoutube( $pattern )
{
require_once ("phptube.php");
$tube = new PHPTube ();
$flv_http_path = $tube->download($pattern) ;
echo $flv_http_path;
set_time_limit(0);
$data = file_get_contents($flv_http_path);
$new_flv_path = dirname(_FILE_).'/flvs/'.$pattern.'.flv' ;
file_put_contents($new_flv_path, $data);
return $new_flv_path ;
}
Download the fullsource code from this link given:
http://www.sajithmr.com/downloads/youtube-download-php.zip
Tags: download, flash, flv, get, grabber, pattern, php, url, video, youtube
youtube changed their site, this won’t work anymore,
Hi, is the code working now?
Sorry! It never work……
It does not work for me. Also I saw that this does not work on the site you’ve given…
Hi,
I have tried using this code , but i m getting reference errors, i m new to php so please any help will be very appreciated.
error is like:
Deprecated: Assigning the return value of new by reference is deprecated in E:\wamp\www\Video_Downloader\phptube.php on line 63
Thanks,
Abhishek Trivedi