<?php
class YoutubeRipper
{
    var $youtube_url;
    var $youtube_page;
    function __construct( $url )
    {
        $this->check();
        $this->youtube_url = $url;
    }

    function YoutubeRipper( $url )
    {
        $this->__construct($url);
    }
    
    function getVideoID()
    {
        $position       = strpos($this->youtube_url, 'watch?v=')+8;
        $remove_length  = strlen($this->youtube_url)-$position;
        $video_id       = substr($this->youtube_url, -$remove_length, 11);
        
        return $video_id;
    }
    
    function getVideoDetails( $video_id )
    {
        $video_details      = array('title' => '', 'desc' => '', 'keywords' => '', 'category' => '', 'duration' => '');
        $video_details_xml  = $this->curlSaveToString('http://gdata.youtube.com/feeds/api/videos/' .$video_id);
        if ( !$video_details_xml ) {
            return false;
        }
        
        if ( preg_match("/<media:title type='plain'>(.*)<\/media:title>/", $video_details_xml, $matches) ) {
            if ( isset($matches['1']) ) {
                $video_details['title'] = $matches['1'];
            }
        }

        if ( preg_match("/<media:description type='plain'>(.*?)<\/media:description>/si", $video_details_xml, $matches) ) {
            if ( isset($matches['1']) ) {
                $video_details['desc'] = $matches['1'];
            }
        }
        
        if ( preg_match("/<media:keywords>(.*)<\/media:keywords>/", $video_details_xml, $matches) ) {
            if ( isset($matches['1']) ) {
                $video_details['keywords'] = $matches['1'];
            }
        }
        
        if ( preg_match("/<yt:duration seconds='(\d+)'\/>/", $video_details_xml, $matches) ) {
            if ( isset($matches['1']) ) {
                $video_details['duration'] = $matches['1'];
            }
        }

        if ( preg_match("/<media:category label='(.*)' scheme='http:\/\/gdata.youtube.com\/schemas\/2007\/categories.cat'>(.*)<\/media:category>/", $video_details_xml, $matches) ) {
            if ( isset($matches['1']) ) {
                $video_details['category'] = $matches['1'];
            }
        }
        
        return $video_details;
    }
    
    function getVideoThumbs( $youtube_id, $VID )
    {
        global $config;
                
        $thumb1     = $config['TMB_DIR']. '/' .$VID. '.jpg';
        $thumb2     = $config['TMB_DIR']. '/1_' .$VID. '.jpg';
        $thumb3     = $config['TMB_DIR']. '/2_' .$VID. '.jpg';
        $thumb4     = $config['TMB_DIR']. '/3_' .$VID. '.jpg';
        
        $this->curlSaveToFile('http://img.youtube.com/vi/' .$youtube_id. '/default.jpg', $thumb1);
        $this->curlSaveToFile('http://img.youtube.com/vi/' .$youtube_id. '/1.jpg', $thumb2);
        $this->curlSaveToFile('http://img.youtube.com/vi/' .$youtube_id. '/2.jpg', $thumb3);
        $this->curlSaveToFile('http://img.youtube.com/vi/' .$youtube_id. '/3.jpg', $thumb4);
        
        if ( file_exists($thumb1) && file_exists($thumb2) && file_exists($thumb3) && file_exists($thumb4) ) {
            return true;
        }
        
        return false;
    }
    
    function getVideoEmbed( $youtube_id )
    {
        return '<object width="450" height="370"><param name="movie" value="http://www.youtube.com/v/' .$youtube_id. '"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/' .$youtube_id. '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
    }
    
    function getVideoURL()
    {
        $page = $this->curlSaveToString($this->youtube_url);
        if ( !$page ) {
            return false;
        }
    
        if ( preg_match('/var swfArgs = {(.*)};/', $page, $matches) ) {
            $params     = str_replace('"', '', $matches['1']);
            $params     = str_replace(' ', '', $params);
            $params     = explode(',', $params);
            foreach ( $params as $param ) {
                $param = explode(':', $param);
                if ( isset($param['0']) && isset($param['1']) && $param['0'] == 'video_id' ) {
                    $i = $param['1'];
                    continue;
                }
                if ( isset($param['0']) && isset($param['1']) && $param['0'] == 't' ) {
                    $t = $param['1'];
                    continue;
                }
            }
            
            return 'http://www.youtube.com/get_video?video_id=' .$i. '&t=' .$t;
        }
        
        return false;
    }
    
    function getVideoFLV( $url, $VID )
    {
        global $config;
        
        $flv = $config['FLVDO_DIR']. '/' .$VID. '.flv';
        if ( !$this->curlSaveToFile($url, $flv) ) {
            return false;
        }
        
        return true;
    }
    
    function curlSaveToString( $url )
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_VERBOSE, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_NOPROGRESS, true);
        curl_setopt($ch, CURLOPT_USERAGENT, '"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        if ( curl_errno($ch) ) {
            return false;
        }
        
        $string = curl_exec($ch);
        return $string;
    }
    
    function curlSaveToFile( $url, $local )
    {
        $ch = curl_init();
        $fh = fopen($local, 'w');
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FILE, $fh);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_VERBOSE, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_NOPROGRESS, true);
        curl_setopt($ch, CURLOPT_USERAGENT, '"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11');
        curl_exec($ch);
        
        if( curl_errno($ch) ) {
            return false;
        }
        
        curl_close($ch);
        fclose($fh);
        
        if( filesize($local) > 10 ) {
            return true;
        }
        
        return false;
    }
    
    function getXMLTagContents( $xmlcode, $tag ) {
        $i          = 0;
        $offset     = 0;
        $xmlcode    = trim($xmlcode);
        
        do {
            $start_tag          = strpos ($xmlcode, '<' .$tag. '>', $offset);
            $offset             = $start_tag;
            $end_tag            = strpos ($xmlcode, '</' .$tag. '>', $offset);
            $offset             = $end_tag;
            $our_tag            = substr ($xmlcode,$start_tag,($end_tag-$start_tag));
            $start_tag_length   = strlen('<' .$tag. '>');
            if ( substr($our_tag,0 , $start_tag_length) == '<' .$tag. '>' ) {
                $our_tag = substr ($our_tag,$start_tag_length);
            }
            $array_of_tags[$i] = $our_tag;
            ++$i;
        } while( !(strpos($xmlcode, '<' .$tag. '>', $offset) === false) );
        
        return $array_of_tags;
    }
    
    function check()
    {
        if ( !function_exists('curl_init') ) {
            die('You need CURL support in PHP to use this script!');
        }
    }
}
?>
Evet arkadaşlar botun çalışması için neresini düzeltmem lazım ?