Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2004
    Location
    London
    Posts
    2,163
    Tokens
    44
    Habbo
    HabbaJabba

    Latest Awards:

    Default YouTube PHP assistance

    I've been attempting to get hold of a script for about 3 days now that will basically get the video ID and the token from a YouTube video, then echo it. Unfortunately, I've failed.

    This is the coding that I'm using...

    PHP Code:
    <?php
    $youtube 
    $_GET['web'];
    function 
    getstring($string)
    {
        
    $pos strrpos($string"swfArgs")+11;
         
    $texto substr($string,$pos,strrpos(substr($string,$pos,strlen($string)), "additionalStatsHonorsUrl")-10);
            
    $replace = array(" ",'"',"_");
        
    $adata split(",",str_replace($replace,"",$texto));
        
    $vid_id split(":",$adata[2]);
        
    $code split(":",$adata[6]);
        
    $vidn1 strrpos($string"<title>")+7;
        
    $vidn2 strrpos(substr($string,$vidn1,-1), "</title>");
        
    $vidname substr($string,$vidn1,$vidn2);
        
    $web 'http://www.youtube.com/get_video?fmt=18&video_id='.$vid_id[1].'&t='.$code[1];
        echo 
    $web.'|'.$vidname;

    function 
    getPage($opts) {
            
    $ch curl_init($opts);
            
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12");
            
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
    curl_setopt($chCURLOPT_HEADER0);
            
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
            
    curl_setopt($chCURLOPT_AUTOREFERER1);
            
    curl_setopt($chCURLOPT_TIMEOUT5);
            
    $html curl_exec($ch);
            if(
    curl_errno($ch)) {
                
    $html "";
            }
            
    curl_close ($ch);
        return 
    getstring($html);
    }
    getPage($youtube);
    ?>
    For example... this YouTube link...

    Code:
    http://www.youtube.com/watch?v=m2vWQFHP3D0
    I should be able to get the video ID from the URL already which is m2vWQFHP3D0 but then I need the token.

    The end product should look like this...

    Code:
    http://www.youtube.com/get_video?fmt=18&video_id=m2vWQFHP3D0&t=vjVQa1PpcFNL59klwGHWg7fOm6Haf1Ytrvgl9NPE32Q=&asv=
    BUT... I get this :S I really don't understand!

    Code:
    http://www.youtube.com/get_video?fmt=18&video_id=//s.ytimg.com/yt/cssbin/www-feather-vfl54jP1d.css><!--[iflteIE7]><linkrel=stylesheethref=http&t=//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gifclass=opera-link></a><ahref=http
    If anyone knows what's up, then please feel free to help. +rep for anyone that contributes well.

  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Here's something I threw together. You can use regex but for the sake of understanding on your end I used explode.

    You can input it into generate_url two different ways and it will still work. You can either input a full URL like $url does, or just give it the movie ID (m2vWQ..etc)

    PHP Code:
    $url "http://www.youtube.com/watch?v=m2vWQFHP3D0";

    function 
    get_movie($url)
    {
        
    $video explode('v='$url);
        
    $video $video[1];
        
    $video explode('&'$video);
        
    $video $video[0];

        return 
    $video;
    }

    function 
    get_token($url)
    {
        
    $html file_get_contents($url);

        
    $token explode('"t": "'$html);
        
    $token explode('",'$token[1]);
        
    $token $token[0];

        return 
    $token;
    }

    function 
    construct_url($video)
    {
        if (
    explode('youtube.com'$video) != -1) {
            
    $token get_token($video);
            
    $video get_movie($video);
        } else {
            
    $token get_token("http://www.youtube.com/watch?v={$video}");
        }

        return 
    "http://www.youtube.com/get_video?fmt=18&video_id={$video}&t={$token}&asv=";
    }


    echo 
    construct_url($url); 

  3. #3
    Join Date
    Jul 2004
    Location
    London
    Posts
    2,163
    Tokens
    44
    Habbo
    HabbaJabba

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    Here's something I threw together. You can use regex but for the sake of understanding on your end I used explode.

    You can input it into generate_url two different ways and it will still work. You can either input a full URL like $url does, or just give it the movie ID (m2vWQ..etc)

    PHP Code:
    $url "http://www.youtube.com/watch?v=m2vWQFHP3D0";

    function 
    get_movie($url)
    {
        
    $video explode('v='$url);
        
    $video $video[1];
        
    $video explode('&'$video);
        
    $video $video[0];

        return 
    $video;
    }

    function 
    get_token($url)
    {
        
    $html file_get_contents($url);

        
    $token explode('"t": "'$html);
        
    $token explode('",'$token[1]);
        
    $token $token[0];

        return 
    $token;
    }

    function 
    construct_url($video)
    {
        if (
    explode('youtube.com'$video) != -1) {
            
    $token get_token($video);
            
    $video get_movie($video);
        } else {
            
    $token get_token("http://www.youtube.com/watch?v={$video}");
        }

        return 
    "http://www.youtube.com/get_video?fmt=18&video_id={$video}&t={$token}&asv=";
    }


    echo 
    construct_url($url); 
    Thank you so much! +rep! (I have to spread, so I'll do it ASAP)

    Only, I have one problem that I've run into. It seems that I can only use the link if I manually do it, because of the I.P. address...

    The part about the "real" URL, the one containing the requester's IP address, is still true. It's based on the requester's IP address and changing the IP address argument will break it. However, try to use the normal mp4 download URL that you get on one computer on a computer on a different network and it will fail with a 403 error.

    ie.
    http://www.youtube.com/get_video?fmt...PHKitNuCdfX8M=


    will work on the computer that you source it from, but won't work on a computer on a different network :/

  4. #4
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    If I remember correctly that is the way the token works...

  5. #5
    Join Date
    Jul 2004
    Location
    London
    Posts
    2,163
    Tokens
    44
    Habbo
    HabbaJabba

    Latest Awards:

    Default

    Surely there's a way of bypassing this?

  6. #6
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default

    You could download it the server using curl and then download from your server? Obviously that uses quite a lot of resources.
    OR rewrite it in javascript, so the client actually generates the url
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


  7. #7
    Join Date
    Jul 2004
    Location
    London
    Posts
    2,163
    Tokens
    44
    Habbo
    HabbaJabba

    Latest Awards:

    Default

    Quote Originally Posted by Joe! View Post
    You could download it the server using curl and then download from your server? Obviously that uses quite a lot of resources.
    OR rewrite it in javascript, so the client actually generates the url
    I've tried curl and that didn't work, just outputted a bunch of crap like I said in my first post. How would I go about doing it in javascript?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •