Ver Mensaje Individual
  #6 (permalink)  
Antiguo 04/11/2012, 09:37
Thecr4s
 
Fecha de Ingreso: noviembre-2012
Mensajes: 15
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Como autopostear videos de Youtube

Encontré este codigo que lo que hace es mostrar los videos de la forma que quiero... pero debes indicar el video no puedes poner el rss.. si alguien me pudiese ayudar a adaptarlo por favor

Este es el codigo

Código:
<?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 youtube($id)
    {
        if (strlen($id) >=22)
        {
            parse_str( parse_url( $id, PHP_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($tempString, 0, $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($tempString, 0, $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($tempString, 0, $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($tempString, 0, $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>';
    }


}

?>

Código:
<?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
 */

require_once 'youtube.class.php';

/*
 * Tambien le pueden pasar como parametro solo el ID de youtube 
 * $youtube = new youtube('59PyU_7iqaU');
 *
 */
$youtube = new youtube('http://www.youtube.com/watch?v=59PyU_7iqaU');

echo 'Titulo: '.$youtube->getTitle().'<br/>';
echo 'Publicado: '.$youtube->getPublished().'<br/>';
echo 'Descripcion: '.$youtube->getDescription().'<br/>';
echo 'Meta Tags: '.$youtube->getMetaTags().'<br/>';
echo 'Link: '.$youtube->getUrl().'<br/>';
echo 'Imagen: '.$youtube->getUrlImage('default').'<br/>';


echo $youtube->getEmbeb(640, 390);

?>