Thursday, April 26, 2012

[YouTube-API] Re: How to get the thumb of a video for youtube.be url.

Hello,

The proper way to do this is to use oEmbed, which will take in a
valid watch page URL and return info about the embed code for it,
including the thumbnail:

http://apiblog.youtube.com/2009/10/oembed-support.html

Otherwise, you just need to update your regex, but that's not really
a question related to the API.

Cheers,
-Jeff Posnick, YouTube API Team
groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
@YouTubeDev


On Apr 26, 1:16 pm, georgiagirl <deuces...@gmail.com> wrote:
> Awhile back I found the code below that gets the thumb of a video from a
> submitted url. The problem is that it works fine for every type of url but
> the youtube.be shortened version. What do I change to this code to make it
> grab the thumb of the youtube.be version aswell as the other versions?
>
>    <code>
>  function get_youtube_screen_link( $url = '', $type = 'default', $echo =
> true ) {
>     if( empty( $url ) )
>         return false;
>
>     if( !isset( $type ) )
>         $type = '';
>
>     $url = esc_url( $url );
>
>     preg_match("|[\\?&]v=([^&#]*)|",$url,$vid_id);
>
>     if( !isset( $vid_id[1] ) )
>         return false;
>
>     $img_server_num =  'i'. rand(1,4);
>
>     switch( $type ) {
>         case 'large':
>             $img_link =
> "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/0.jpg";
>             break;
>         case 'first':
>             // Thumbnail of the first frame
>             $img_link =
> "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/1.jpg";
>             break;
>         case 'small':
>             // Thumbnail of a later frame(i'm not sure how they determine
> this)
>             $img_link =
> "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/2.jpg";
>             break;
>         case 'default':
>         case '':
>         default:
>             $img_link =
> "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/default.jpg";
>             break;
>     }
>     if( $echo )
>         echo $img_link;
>     else
>         return $img_link;
>
> }
>
> </code>

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment