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: , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

55 Responses to “Download Youtube Videos using PHP Code”

  1. Paul says:

    youtube changed their site, this won’t work anymore,

  2. Crystal says:

    Hi, is the code working now?

  3. ugesh says:

    Sorry! It never work……

  4. Fakeheal says:

    It does not work for me. Also I saw that this does not work on the site you’ve given…

  5. abhishek trivedi says:

    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

· · · ◊ ◊ ◊ · · ·

Leave a Reply

وظائف 2011 تحويل العملات برامج برنامج تسريع التحميل برنامج الفلاش برنامج محول الصوتيات عربي hotel 2011 زيادة رواتب العساكر 1431