Welcome, guest | Sign In | My Account | Store | Cart

This is a series of function that you can use to download video(s) from Youtube.com

PHP, 44 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/*

	This is a basic functions used to show real URI of FLV files at youtube.com so we can
	download the file and play it offline. 
*/

function get_content_of_url($url){
	$ohyeah = curl_init();
	curl_setopt($ohyeah, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ohyeah, CURLOPT_URL, $url);
	$data = curl_exec($ohyeah);
	curl_close($ohyeah);
	return $data;
}


function get_flv_link($string) {  
	if (eregi("watch_fullscreen(.*)plid", $string, $out)) {  
		$outdata = $out[1];
	}  
	$arrs = (explode('&',$outdata));
	foreach($arrs as $arr){
		list($i,$x) = explode("=",$arr);
		$$i = $x;
	}
	$link = 'http://www.youtube.com/get_video?video_id='.$video_id.'&t='.$t;
	return array($video_id,$link);
} 

function get_youtube($url){
	$stream = get_content_of_url($url);
	return get_flv_link($stream);
}


/* ######## SAMPLE OF USAGE ##########
 * <?php
 * require_once('youtube.lib.php');
 * $link = get_youtube($youtube_url); 
 * echo $link[0];
 * ?>
 * 
 */

2 comments

Regie Mon Averion 11 years, 7 months ago  # | flag

i think it's not working any more. do you have an updated script?

Andy Gee 10 years, 6 months ago  # | flag

I've made a new one here which you can search for, download and play entire playlists: http://dumaguetewebdesign.com/youtube.php demo available too ;)

Created by yeni setiawan on Wed, 3 Dec 2008 (MIT)
PHP recipes (51)
yeni setiawan's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks