Ver Mensaje Individual
  #2 (permalink)  
Antiguo 06/11/2011, 08:09
Avatar de Patriarka
Patriarka
 
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 3 meses
Puntos: 288
Respuesta: Obtención de YT thumbnail

hay te va una clase que todo lo resuelve:

<? $youtube_id = $Video->getLink(); ?>
<?php $youtube = new youtube($youtube_id);?>
<a href="<?php echo $Video->getLink(); ?>" rel="vidbox" title="<?php echo $Video->getTitle(); ?>"><img src="<?php echo $youtube->getUrlImage('grande'); ?>" width="190" height="123"/></a>

clase youtuve
<?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
*/

Código PHP:
Ver original
  1. class youtube
  2. {
  3.     var $data = '';
  4.     var $id = '';
  5.  
  6.     public function youtube($id)
  7.     {
  8.         if (strlen($id) >=22)
  9.         {
  10.             parse_str( parse_url( $id, PHP_URL_QUERY ) );
  11.             //http://www.youtube.com/v/
  12.             //http://youtu.be/-c1ltzu8sKQ
  13.             if(isset($v)){
  14.                 $this->id = $v;
  15.             }else{
  16.                 $v=explode("/", $id);
  17.                 //var_dump($v);
  18.                 $this->id = $v[3];
  19.             }
  20.  
  21.         }
  22.         else
  23.         {
  24.             $this->id=$id;
  25.         }
  26.         $url = "http://gdata.youtube.com/feeds/videos/".$this->id;
  27.         $browser_id = "none";
  28.         $curl_handle = curl_init();
  29.         $options = array
  30.         (
  31.             CURLOPT_URL=>$url,
  32.             CURLOPT_HEADER=>false,
  33.             CURLOPT_RETURNTRANSFER=>true,
  34.             CURLOPT_USERAGENT=>$browser_id
  35.         );
  36.         curl_setopt_array($curl_handle,$options);
  37.         $server_output = curl_exec($curl_handle);
  38.         curl_close($curl_handle);
  39.  
  40.         $this->data=$server_output;
  41.     }
  42.  
  43.     public function getTitle()
  44.     {
  45.         $startString = "<media:title type='plain'>";
  46.         $endString = "</media:title>";
  47.  
  48.         $tempString = strstr($this->data, $startString);
  49.  
  50.         $endLocation = strpos($tempString, $endString);
  51.         $title = substr($tempString, 0, $endLocation);
  52.  
  53.         if (empty($title))
  54.         {
  55.             $title=false;
  56.         }
  57.         else
  58.         {
  59.             $title=substr($title,strlen($startString));
  60.         }
  61.  
  62.         return $title;
  63.     }
  64.  
  65.     public function getPublished()
  66.     {
  67.         $startString = "<published>";
  68.         $endString = "</published>";
  69.  
  70.         $starLocation = strpos($this->data, $startString);
  71.         $tempString = substr($this->data, $starLocation);
  72.  
  73.         $endLocation = strpos($tempString, $endString);
  74.         $published = substr($tempString, 0, $endLocation);
  75.  
  76.         if (empty($published))
  77.         {
  78.             $published=false;
  79.         }
  80.         else
  81.         {
  82.             $published=substr($published,strlen($startString));
  83.             $published=substr($published,0,10);
  84.         }
  85.  
  86.         return $published;
  87.     }
  88.  
  89.     public function getDescription()
  90.     {
  91.         $startString = "<media:description type='plain'>";
  92.         $endString = "</media:description>";
  93.  
  94.         $starLocation = strpos($this->data, $startString);
  95.         $tempString = substr($this->data, $starLocation);
  96.  
  97.         $endLocation = strpos($tempString, $endString);
  98.         $description = substr($tempString, 0, $endLocation);
  99.  
  100.         if (empty($description))
  101.         {
  102.             $description=false;
  103.         }
  104.         else
  105.         {
  106.             $description=substr($description,strlen($startString));
  107.         }
  108.  
  109.         return $description;
  110.     }
  111.  
  112.     public function getMetaTags()
  113.     {
  114.         $startString = "<media:keywords>";
  115.         $endString = "</media:keywords>";
  116.  
  117.         $starLocation = strpos($this->data, $startString);
  118.         $tempString = substr($this->data, $starLocation);
  119.  
  120.         $endLocation = strpos($tempString, $endString);
  121.         $metaTags = substr($tempString, 0, $endLocation);
  122.  
  123.         if (empty($metaTags))
  124.         {
  125.             $metaTags=false;
  126.         }
  127.         else
  128.         {
  129.             $metaTags=substr($metaTags,strlen($startString));
  130.         }
  131.  
  132.         return $metaTags;
  133.     }
  134.  
  135.     public function getUrl()
  136.     {
  137.         return "http://www.youtube.com/watch?v=".$this->id;
  138.     }
  139.  
  140.     public function getUrlImage($option)
  141.     {
  142.         if($option=='default')
  143.         {
  144.             return 'http://i.ytimg.com/vi/'.$this->id.'/default.jpg';
  145.         }
  146.         if($option=='grande')
  147.         {
  148.             return 'http://i.ytimg.com/vi/'.$this->id.'/0.jpg';
  149.         }
  150.         if($option==1)
  151.         {
  152.             return 'http://i.ytimg.com/vi/'.$this->id.'/1.jpg';
  153.         }
  154.         if($option==2)
  155.         {
  156.             return 'http://i.ytimg.com/vi/'.$this->id.'/2.jpg';
  157.         }
  158.         if($option==3)
  159.         {
  160.             return 'http://i.ytimg.com/vi/'.$this->id.'/3.jpg';
  161.         }
  162.     }
  163.  
  164.     public function getEmbeb($width, $height)
  165.     {
  166.         $autoplay = 1;
  167.         return '<iframe class="youtube-player" type="text/html" width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$this->id.'?autoplay='.$autoplay.'" frameborder="0">
  168.        </iframe>';
  169.     }
  170.  
  171.  
  172. }
  173.  
  174. ?>