by Reinchek on Tue May 27, 2008 10:41 pm
Passando come primo argomento allo script un link di youtube il programma genererà il link per il download diretto del video:
- Code: Select all
<?php
logo();
if ($argc < 2 ) {
usage();
die();
}
else {
$link = $argv[1]; // Link which to work
link_ok($link);
$video_id = video_ID($link); // Id of video
$link_mod = replace_slash($link); // Replace the "?" after "watch" with "/"
// and "=" after "v" with "/"
$t = get_link($link_mod);
$link_final = "http://www.youtube.com/get_video?video_id=".$video_id."&t=".$t."\n";
link_ok($link);
echo "\t\tLink generated\n";
echo "\t*************************************************************\n";
echo "\t".$link_final." \n";
echo "\t*************************************************************\n\n\n\n";
}
function logo() {
echo "\t*********************************************\n";
echo "\t* Author: Reinchek *\n";
echo "\t* Site: http://reinchek.altervista.org *\n";
echo "\t* Program: YouT Link Download Gen *\n";
echo "\t* *\n";
echo "\t*********************************************\n";
}
function usage() {
echo "\t\tyoutd.php <link of video>\n";
echo "\t\t\tExample \n";
echo "\tyoutd.php http://it.youtube.com/watch?v=sJaAEhHYn73\n\n\n";
}
function link_ok($link) {
$link_ok = "^(http://)";
if ( !ereg($link_ok, $link) ) {
echo "Error: the shape of the link is wrong\n";
echo "Example of the correct link: \n";
echo "http://www.youtube.com/watch?v=sJaAEhHYn73\n";
die();
}
}
function video_ID($link) {
$reg = "v=?.{11}";
$reg2 = "[^v\=](.*){11}";
ereg($reg, $link, $extract);
ereg($reg2, $extract[0], $video_id);
return $video_id[0];
}
function replace_slash($link) {
$reg = "[^(watch)]?\?";
$reg2 = "[^\?v]?\=";
$link_mod = $link;
$link = ereg_replace($reg , "/", $link); //Find the "?" in the link
$link = ereg_replace($reg2, "/", $link); //Find the = symbol in the link
return $link;
}
function get_link($link_mod) {
$server = "www.youtube.com";
$port = 80;
$request = "GET ".$link_mod." HTTP/1.0\r\n";
$request .= "Host: ".$server."\r\n";
$request .= "Connection: Close\r\n\r\n";
$reg = "&t\=(.){33}";
$reg2 = "[^(&t\=)](.)*";
$found = 0;
if ( ($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
echo "\nErrore durante la creazione del socket\nMotivo: ".socket_strerror($sock)."\n";
else {
$results = socket_connect($sock, $server, $port);
if ($results < 0) echo "Errore durante la connessione: ".socket_strerror($sock)."\n";
else {
socket_write($sock, $request, strlen($request));
while ($response = socket_read($sock, 200))
if ( ereg($reg, $response, $t) ) {
ereg($reg2, $t[0], $t);
$trovato = 1;
}
else $trovato = 0;
if ($trovato == 0)
die("\nLink not found ... closing underway ... \n\n\n");
}
socket_close($sock);
}
return $t[0];
}
?>