0

So my string is

<div class="cm-video">
<iframe width="100%" height="100%" src="http://www.youtube.com/embed/ATYklyGZU4I?feature=oembed" frameborder="0" allowfullscreen></iframe>
</div>

I've read How do I get a YouTube video thumbnail from the YouTube API? but not sure about how to specifically retrieve the image

Community
  • 1
  • 1
pee2pee
  • 3,619
  • 7
  • 52
  • 133

3 Answers3

0

Just call an <img> element with the desired format, for example php:

$id = "ATYklyGZU4I";
echo "<img src=http://img.youtube.com/vi/$id/1.jpg>";

other formats are mentioned in your link.

Som1
  • 60
  • 8
0

Try with this code it will give you the url of video image.

$url = "http://www.youtube.com/embed/ATYklyGZU4I?feature=oembed";
echo getYouTubeVideoImage($url);

function getYouTubeVideoImage($youtube_code){
    preg_match('/youtube\.com\/v\/([\w\-]+)/', $youtube_code, $match);


    if(!isset($match[1]) || $match[1] == ''){
        preg_match('/youtube\.com\/embed\/([\w\-]+)/', $youtube_code, $match);
    }
    if(!isset($match[1]) || $match[1] == ''){
        preg_match('/v\=(.+)&/',$youtube_code ,$match);
    }

    $full_size_thumbnail_image = "http://img.youtube.com/vi/".$match[1]."/0.jpg";
    $small_thumbnail_image1 = "http://img.youtube.com/vi/".$match[1]."/1.jpg";
    $small_thumbnail_image2 = "http://img.youtube.com/vi/".$match[1]."/2.jpg";
    $small_thumbnail_image3 = "http://img.youtube.com/vi/".$match[1]."/3.jpg";

    // return whichever thumbnail image you would like to retrieve
    return $full_size_thumbnail_image;      
}
Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
0
 let

$videoURL = "https://www.youtube.com/watch?v=MVQOmonaFOg";

$videoAPI = "https://www.youtube.com/oembed?format=json&url=";

$data = json_decode(file_get_contents($videoAPI . urlencode($videoURL)));

print_r($data);