download video youtube

Stato
Discussione chiusa ad ulteriori risposte.

dimiandre

Utente Electrum
31 Dicembre 2009
159
14
31
109
ciao a tutti :)
vorrei capire come é possibile fare un programma che permetta di scaricare video da youtube.. sto usando le data api ufficiali di youtube ma senza successo non riesco a prendere il video originale.. qualcuno sà come si fà?
grazie anticipatamente delle risposte ^^
 
Ho trovato questo, spero possa servirti (se vuoi lo commentiamo un pò)



lg.php


<?php
// first function, read HTML from youtube
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;
}

// second function, get path that lead into movie files
function get_flv_link($string) {
if (
preg_match('/\/player2\.swf\?(.*)", "movie_player"/', $string, $match)) {
$url = $match[1];
return
'http://youtube.com/get_video.php?'.$url;
}
}

// third function, read header returned by second function above
function get_http_header($url){
$uh = curl_init();
curl_setopt($uh, CURLOPT_URL, $url);
curl_setopt($uh, CURLOPT_HEADER, 1);
curl_setopt($uh, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($uh);
curl_close($uh);
return
$res;
}

// fourth function, parse the header and show only the link
function show_url($http_header){
$arai = explode("\n",$http_header);
foreach(
$arai as $ini){
if(
eregi("location",$ini)) $url = $ini;
}
list(
$sampah,$hasil) = explode("Location:",$url);
return
str_replace("\n","",trim($hasil));
}

// fifth function, join the four functions above
function download_youtube($url){
$data = get_content_of_url($url);
$next_url = get_flv_link($data);
$data = get_http_header($next_url);
return
show_url($data);
}
?>



Usage Example


lg.php

cm

lg.php


<?php
error_reporting
(0); // <-- to eliminate error report
ini_set("max_execution_time",0); // <-- to avoid operation timed out
echo download_youtube("http://youtube.com/watch?v=O-Tt229laCE");
?>
 
Stato
Discussione chiusa ad ulteriori risposte.