Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá, pessoal gostaria da ajuda para resolver este problema bem simples, tenho um função de pega thumb do vídeo do Youtube, os meus videos estão em BD's. Como fazer isto.
BD's fica da seguinte forma
ID
url
titulo
data
<?php echo parse_youtube_url('http://youtu.be/CHAMA_URL','hqthumb'); ?>
Aqui mostra imagem do Youtube
> <img src="<?php echo parse_youtube_url('http://youtu.be/0IiMopuE-9k','hqthumb'); ?>" alt="" width="250" height="133">
Função:
<?/*
* parse_youtube_url() PHP function
* Author: takien
* URL: http://takien.com
*
* @param string $url URL to be parsed, eg:
* http://youtu.be/zc0s358b3Ys,
* @param string $return what to return
* - embed, return embed code
* - thumb, return URL to thumbnail image
* - hqthumb, return URL to high quality thumbnail image.
* @param string $width width of embeded video, default 560
* @param string $height height of embeded video, default 349
* @param string $rel whether embeded video to show related video after play or not.
*/
function parse_youtube_url($url,$return='embed',$width='',$height='',$rel=0){
$urls = parse_url($url);
//url is [http://youtu.be/xxxx](http://youtu.be/xxxx)
if($urls['host'] == 'youtu.be'){
$id = ltrim($urls['path'],'/');
}
//url is [http://www.youtube.com/embed/xxxx](http://www.youtube.com/embed/xxxx)
else if(strpos($urls['path'],'embed') == 1){
$id = end(explode('/',$urls['path']));
}
//url is xxxx only
else if(strpos($url,'/')===false){
$id = $url;
}
//http://www.youtube.com/watch?feature=player_embedded&v=m-t4pcO99gI
//url is [http://www.youtube.com/watch?v=xxxx](http://www.youtube.com/watch?v=xxxx)
else{
parse_str($urls['query']);
$id = $v;
if(!empty($feature)){
$id = end(explode('v=',$urls['query']));
}
}
//return embed iframe
if($return == 'embed'){
return '</pre>
<iframe src="[http://www.youtube.com/embed/'.$id.'?rel='.$rel.'"](http://www.youtube.com/embed/) frameborder="0" width="'.($width?$width:560).'" height="'.($height?$height:349).'"></iframe>
<pre>';
}
//return normal thumb
else if($return == 'thumb'){
return 'http://i1.ytimg.com/vi/'.$id.'/default.jpg';
}
//return hqthumb
else if($return == 'hqthumb'){
return 'http://i1.ytimg.com/vi/'.$id.'/hqdefault.jpg';
}
// else return id
else{
return $id;
}
}
?>Carregando comentários...