<code>
<?php
require_once(ABSPATH.'wp-includes/class-oembed.php');
$oembed= new WP_oEmbed;
$name = get_post_meta($post->ID,'video_code',true);
$url = $name;
//As noted in the comments below, you can auto-detect the video provider with the following
$provider = $oembed->discover($name);
//$provider = 'http://www.youtube.com/oembed';
$video = $oembed->fetch($provider, $url, array('width' => 300, 'height' => 175));
$thumb = $video->thumbnail_url; if ($thumb) { ?>
<img src="<?php echo $thumb; ?>" width="66px" height="66px" />
<?php } ?>
</code>
On Thursday, April 26, 2012 7:05:03 PM UTC-4, georgiagirl wrote:
-- On Thursday, April 26, 2012 7:05:03 PM UTC-4, georgiagirl wrote:
Ok I use wordpress and I allow users to submit youtube url's for a video from the front end which I store in a custom field. I didn't see anything on Oembed that explained how I could use it with this method. Can you by any chance point me to the documentation that will help me figure this out?
On Thursday, April 26, 2012 4:12:41 PM UTC-4, Jeffrey Posnick wrote: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 view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/wmcV2l3ioXkJ.
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