How to get a static image of youtube video using javascript?

In video galleries, YouTube displays images of a video, not a flash player. If you click on the image, you will be redirected to the page where the flash video player is located. I want to show the first static images.

How can I do this programmatically?

+6
youtube image video
source share
2 answers

For Javascript: (I assume you marked it as a flash because Youtube is a flash player)

function getScreen( url, size ) { if(url === null){ return ""; } size = (size === null) ? "big" : size; var vid; var results; results = url.match("[\\?&]v=([^&#]*)"); vid = ( results === null ) ? url : results[1]; if(size == "small"){ return "http://img.youtube.com/vi/"+vid+"/2.jpg"; }else { return "http://img.youtube.com/vi/"+vid+"/0.jpg"; } } 

Found here .

Disabling this function, basically you just need to take the v = ladlfasd parameter and put it in this URL:

 http://img.youtube.com/vi/(v= parameter)/2.jpg 

Where is it 2.jpg for small, 0.jpg for large

+9
source share
 function getYoutubeThumbnail($url) { if(preg_match('![?&]{1}v=([^&]+)!', $url . '&', $m)) { $videoid = $m[1]; } else if(preg_match('~/v/([0-9a-z_]+)~i', $url, $m)) { $videoid = $m[1]; } $youtube_thumbnail = 'http://img.youtube.com/vi/' . $videoid . '/default.jpg'; $c = curl_init(); $url = trim($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, $url); $contents = curl_exec($c); curl_close($c); $feed = "http://gdata.youtube.com/feeds/api/videos/".$videoid; $newInfo = trim(@file_get_contents($feed)); preg_match('/<media:title(.*?)<\/media:title>/', $newInfo, $result); $title = strip_tags($result[0]); preg_match('/<media:keywords(.*?)<\/media:keywords>/', $newInfo, $result); $desc = strip_tags(str_replace(",", "", $result[0])); //embed path $embed_path = "http://www.youtube.com/embed/".$videoid; $youtube_info = array('videoid' => $videoid,'title' => $title, 'description' => $desc,'youtube_thumbnail' => $youtube_thumbnail,'embed_path' => $embed_path) ; return $youtube_info; } 
+3
source share

All Articles