“How to get the Google video's thumbnail image ? ” in PHP or Javascript?
-
20-08-2019 - |
Question
I want to use the thumbnail of the Google video's. In PHP or JavaScript function
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"; }
}
for the you tube vedio
imgUrl_big = getScreen("uVLQhRiEXZs");
imgUrl_small = getScreen("uVLQhRiEXZs", 'small');
Solution
Here is a small script that maybe gets the job done the way you want it:
<?php
$content = file_get_contents("http://video.google.de/?hl=de&tab=wv");
$regex = '|<img class=thumbnail-img.*?src=(.*?) |';
preg_match_all($regex, $content, $result, PREG_PATTERN_ORDER);
$images = $result[1];
foreach($images AS $image){
echo $image;
}
?>
OTHER TIPS
You can pull an RSS view (parse-able with your favorite XML library) view appending "&output=rss" to any google video search. The thumbnail for each video can be found in the <media:thumbnail> tag.
A search for "Stackoverflow", with rss view.
There seems to be a pattern here. In that every thumbnail image takes the form of http://*.gvt0.com/vi//default.jpg where * is a digit (I've seen 0 & 3, presumably there are more). So, if you know the video's id, you can pull the thumbnail without searching for it. There used to be a better way to do this, but now that Google Video ~= Youtube I think you're stuck with this hack-ish solution.
The thumbnail of the first image from the above rss feed.
Basically:
function getThumbnail($id)
{
return 'http://0.gvt0.com/vi/'.$id.'/default.jpg';
}