[PHP] YouTDLG Youtube download link generator

Only PHP & MySQL.

Moderator: DaD

[PHP] YouTDLG Youtube download link generator

Postby 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];
}
?>
La mente umana è come un paracadute, funziona solo se si apre!

http://bux.to/?r=Reinchek
Reinchek
Newbies
 
Posts: 8
Joined: Thu May 22, 2008 11:50 pm

[PHP] YouTDLG Youtube download link generator

Sponsor

Sponsor


Re: [PHP] YouTDLG Youtube download link generator

Postby k8 on Wed May 28, 2008 2:21 pm

Ho dato una lettura veloce al codice,
molto molto carino :D & originale come script ;)


Benvenuto :clap:
Big-Bug cerca collaboratori.
Scrivete senza abbreviazioni e senza k, grazie.
k8
Admin
 
Posts: 2127
Joined: Tue Jun 06, 2006 4:00 pm

Re: [PHP] YouTDLG Youtube download link generator

Postby Reinchek on Wed May 28, 2008 4:14 pm

Grazie per i complimenti e per il benvenuto .. :D
La mente umana è come un paracadute, funziona solo se si apre!

http://bux.to/?r=Reinchek
Reinchek
Newbies
 
Posts: 8
Joined: Thu May 22, 2008 11:50 pm

Re: [PHP] YouTDLG Youtube download link generator

Postby DaD on Sat May 31, 2008 11:55 am

Davvero buon lavoro, dopo se ho tempo me lo spulcio un pò :D
Image
Le tre grandi virtù di un programmatore: pigrizia, impazienza e arroganza. (Larry Wall)
Get Slack! | User Linux's ID | Blog
User avatar
DaD
Php Guru
 
Posts: 322
Joined: Sat Nov 25, 2006 5:09 pm

Re: [PHP] YouTDLG Youtube download link generator

Postby Reinchek on Sat May 31, 2008 9:20 pm

dad wrote:Davvero buon lavoro, dopo se ho tempo me lo spulcio un pò :D
lol
comunque grazie ringrazio!
La mente umana è come un paracadute, funziona solo se si apre!

http://bux.to/?r=Reinchek
Reinchek
Newbies
 
Posts: 8
Joined: Thu May 22, 2008 11:50 pm


Return to PHP & MySQL

Who is online

Users browsing this forum: No registered users and 1 guest

cron