Miniaturas Youtube e Vimeo

Miniaturas Youtube e Vimeo

<?php
 function getVimeo( $video )
{
 $hash = unserialize( file_get_contents( "http://vimeo.com/api/v2/video/$video.php" ) );
 echo $hash[0]['thumbnail_medium'];
}

function getYoutube( $video )
{
 $hash = file_get_contents( "http://youtube.com/get_video_info?video_id=$video" );
 parse_str( $hash, $arr );
 echo $arr['thumbnail_url'];
}
?>
   <h1>Youtube</h1>
   <img alt="" src="<?=getYoutube('Vg6LtMlHY_A')?>" />
   <h1>Vimeo</h1>
   <img alt="" src="<?=getVimeo('251266')?>" />

Os códigos passados devem ser retirados dos links, no caso, o texto em vermelho
nos links abaixo:

Demo

Download

Este post tem 12 comentários

  1. Falcão Melo

    Rafael, vc saberia como pegar o título e descrição do youtube e vimeo?

    1. Rafael Clares

      Fala Falcão, seguem as funções:

      function getThumbYoutube( $video )
      {
      $hash = file_get_contents( “http://youtube.com/get_video_info?video_id=$video” );
      parse_str( $hash, $arr );
      return utf8_decode( $arr[‘thumbnail_url’] );
      }

      function getTitleYoutube( $video )
      {
      $hash = file_get_contents( “http://youtube.com/get_video_info?video_id=$video” );
      parse_str( $hash, $arr );
      return utf8_decode( $arr[‘title’] );
      }

      function getThumbVimeo( $video )
      {
      $hash = unserialize( file_get_contents( “http://vimeo.com/api/v2/video/$video.php” ) );
      return $hash[0][‘thumbnail_medium’];
      }

      function getTitleVimeo( $video )
      {
      $hash = unserialize( file_get_contents( “http://vimeo.com/api/v2/video/$video.php” ) );
      return $hash[0][‘video_title’];
      }

      echo getTitleYoutube(“Vg6LtMlHY_A”);
      echo getTitleVimeo(“251266”);

  2. Tiago Agostinho

    Rafael, como eu faço pra pegar de os video que ta cadastrado em um banco de dados?

    1. Rafael Clares

      Tiago, daí seria legal eu saber como está cadastrado no banco… você precisa dar mais detalhes.

  3. Molô Assis

    Boa tarde Rafael, está me retornando os seguintes erros…

    ===================================================

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/jammal/public_html/fb/joao/videos/index.php on line 78

    Warning: file_get_contents(http://youtube.com/get_video_info?video_id=Lhn2wPkA8Xg) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/jammal/public_html/fb/joao/videos/index.php on line 78

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/jammal/public_html/fb/joao/videos/index.php on line 72

    Warning: file_get_contents(http://vimeo.com/api/v2/video/46174971.php) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/jammal/public_html/fb/joao/videos/index.php on line 72

    ===================================================

    Tem alguma sugestão?

    1. Rafael Clares

      Crie um arquivo php.ini com o conteúdo:
      allow_url_fopen=on

      Coloque o arquivo na raiz da aplicação

  4. Molô Assis

    espantado com sua velocidade de respota.. kkk
    amigo.. funcionou apenas com o vimeo, o youtube parou de dar erro, mas tbm nao aparece nada ..

  5. Luiz Luque

    Boa tarde Rafael, o script para pegar o titulo não está funcionando com o Vimeo.

    function getTitleVimeo( $video )
    {
    $hash = unserialize( file_get_contents( “http://vimeo.com/api/v2/video/$video.php” ) );
    return $hash[0][‘video_title’];
    }

    e não da nenhuma msn de erro,

    do youtube está funcionado perfeitamente.

    grato por ajudar

    1. Rafael Clares

      Luiz, estou vendo que na minha demo funciona normalmente.
      Olha, crie (ou adicione ao seu) um php.ini com a seguinte linha:

      allow_url_fopen=on

      Isso irá habilitar o file_get_contents;

  6. Youto Yokodera

    Rafael Clares vc poderia me ajudar? eu queria saber como colocara miniatura dos videos da uol

    1. Rafael Clares

      Youto, desculpe mas não tenho ideia, na verdade, nem sabia que tinha vídeos lá.

Deixe um comentário