Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/03/2012, 18:44
Avatar de blakmetall
blakmetall
 
Fecha de Ingreso: diciembre-2010
Ubicación: Jalisco
Mensajes: 181
Antigüedad: 13 años, 4 meses
Puntos: 18
Respuesta: Función regular de youtube

Tengo este codigo:


modificalo para que se llene a tu requerimiento.
Código PHP:

include "la_clase_de_youtube.php";
$error false;
            
$aError = array();
            
            
$url trim($this->data['url']); //la url que ingresen de youtube
            
if(strpos($url,'http://') === false){
                
$url 'http://'$url;
            }

            
$valid_url strpos($url,'http://www.youtube.com/watch?v=');
            if( 
$valid_url === false){
                
$error true;
                
$aError[] = 'Introduce una url valida';
            }else{
                
//creacion del objeto
                
$youtube = new youtube($url);
                
                
$title $youtube->getTitle();
                if(empty(
$title)){
                    
$error true;
                    
$aError[] = 'Introduce una url valida';
                }
            }
            
            
            
            if(!
$error){
                
$youtube_data = array();
                
$youtube_data['title'] = $youtube->getTitle();
                
$youtube_data['published'] = $youtube->getPublished();
                
$youtube_data['description'] = $youtube->getDescription();
                
$youtube_data['url'] = $youtube->getUrl();
                
$youtube_data['url_image'] = $youtube->getUrlImage('default');
                
$youtube_data['embed'] = $youtube->getEmbeb(620370);
                
                
$json_data json_encode($youtube_data);
            }else{
                
$json_data json_encode($aError);
            } 

la_clase_de_youtube.php
Código PHP:
<?php
/*
 * Name: Simple Class Info YouTube
 * Description: Get Information of video YouTube
 * Development: Chuecko
 * Site: http://www.zarpele.com.ar
 * License: GNU GENERAL PUBLIC LICENSE (http://www.gnu.org/licenses/gpl.html)
 * Version: 1.0
 */

class Youtube
{
    var 
$data '';
    var 
$id '';

    public function 
__construct($id)
    {
        if (
strlen($id) >=22)
        {
            
parse_strparse_url$idPHP_URL_QUERY ) );
            
$this->id $v;
        }
        else
        {
            
$this->id=$id;
        }

        
$url "http://gdata.youtube.com/feeds/videos/".$this->id;
        
$browser_id "none";
        
$curl_handle curl_init();
        
$options = array
        (
            
CURLOPT_URL=>$url,
            
CURLOPT_HEADER=>false,
            
CURLOPT_RETURNTRANSFER=>true,
            
CURLOPT_USERAGENT=>$browser_id
        
);
        
curl_setopt_array($curl_handle,$options);
        
$server_output curl_exec($curl_handle);
        
curl_close($curl_handle);

        
$this->data=$server_output;
    }

    public function 
getTitle()
    {
        
$startString "<media:title type='plain'>";
        
$endString "</media:title>";

        
$tempString strstr($this->data$startString);

        
$endLocation strpos($tempString$endString);
        
$title substr($tempString0$endLocation);

        if (empty(
$title))
        {
            
$title=false;
        }
        else
        {
            
$title=substr($title,strlen($startString));
        }

        return 
$title;
    }

    public function 
getPublished()
    {
        
$startString "<published>";
        
$endString "</published>";

        
$starLocation strpos($this->data$startString);
        
$tempString substr($this->data$starLocation);

        
$endLocation strpos($tempString$endString);
        
$published substr($tempString0$endLocation);

        if (empty(
$published))
        {
            
$published=false;
        }
        else
        {
            
$published=substr($published,strlen($startString));
            
$published=substr($published,0,10);
        }

        return 
$published;
    }

    public function 
getDescription()
    {
        
$startString "<media:description type='plain'>";
        
$endString "</media:description>";

        
$starLocation strpos($this->data$startString);
        
$tempString substr($this->data$starLocation);

        
$endLocation strpos($tempString$endString);
        
$description substr($tempString0$endLocation);

        if (empty(
$description))
        {
            
$description=false;
        }
        else
        {
            
$description=substr($description,strlen($startString));
        }

        return 
$description;
    }

    public function 
getMetaTags()
    {
        
$startString "<media:keywords>";
        
$endString "</media:keywords>";

        
$starLocation strpos($this->data$startString);
        
$tempString substr($this->data$starLocation);

        
$endLocation strpos($tempString$endString);
        
$metaTags substr($tempString0$endLocation);

        if (empty(
$metaTags))
        {
            
$metaTags=false;
        }
        else
        {
            
$metaTags=substr($metaTags,strlen($startString));
        }

        return 
$metaTags;
    }

    public function 
getUrl()
    {
        return 
"http://www.youtube.com/watch?v=".$this->id;
    }

    public function 
getUrlImage($option)
    {
        if(
$option=='default')
        {
            return 
'http://i.ytimg.com/vi/'.$this->id.'/default.jpg';
        }
        if(
$option=='grande')
        {
            return 
'http://i.ytimg.com/vi/'.$this->id.'/0.jpg';
        }
        if(
$option==1)
        {
            return 
'http://i.ytimg.com/vi/'.$this->id.'/1.jpg';
        }
        if(
$option==2)
        {
            return 
'http://i.ytimg.com/vi/'.$this->id.'/2.jpg';
        }
        if(
$option==3)
        {
            return 
'http://i.ytimg.com/vi/'.$this->id.'/3.jpg';
        }
    }

    public function 
getEmbeb($width$height)
    {
        
$autoplay 1;
        return 
'<iframe class="youtube-player" type="text/html" width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$this->id.'?autoplay='.$autoplay.'" frameborder="0">
        </iframe>'
;
    }

}
__________________
To the end....