Hi, I am looking for a php function which gets 3 youtube thumbnails based on the ?v= value from youtube ??
<?php /* @Function: YouTube Thumbnail Fetcher @Author: Dan Mcdonald. @Date: 21/05/2009 */ function get_thumbs($youtube_url){ $youtube_url = trim(str_replace(array("http://", "www."), "", strtolower($youtube_url))); if(preg_match("/youtube\.com\/watch\?v=([a-z0-9]*)/i", $youtube_url)){ preg_match_all("/http:\/\/i1\.ytimg\.com\/vi\/([A-Za-z0-9]*)\/default\.jpg/", file_get_contents("http://www.".$youtube_url), $thumbs); return print_r($thumbs[0]); } else { return false; } } get_thumbs("http://www.youtube.com/watch?v=dPdTAg_krJI"); ?> PHP: Enjoy
thx, hmm with $test = getThumbs i get Array ( [0] => http://i1.ytimg.com/vi/lHjNmyzrVvM/default.jpg [1] => http://i1.ytimg.com/vi/lHjNmyzrVvM/default.jpg [2] => http://i1.ytimg.com/vi/DwzakwE2axI/default.jpg [3] => http://i1.ytimg.com/vi/DwzakwE2axI/default.jpg [4] => http://i1.ytimg.com/vi/p7gjK3OgUM0/default.jpg [5] => http://i1.ytimg.com/vi/p7gjK3OgUM0/default.jpg [6] => http://i1.ytimg.com/vi/pUr6nN8YkDU/default.jpg [7] => http://i1.ytimg.com/vi/pUr6nN8YkDU/default.jpg [8] => http://i1.ytimg.com/vi/HthL62uI3ZU/default.jpg [9] => http://i1.ytimg.com/vi/HthL62uI3ZU/default.jpg [10] => http://i1.ytimg.com/vi/pUr6nN8YkDU/default.jpg [11] => http://i1.ytimg.com/vi/pUr6nN8YkDU/default.jpg ) Code (markup): how would i get say the 3 $test[3]??? btw i am looking for the last 3 video i uploaded or my favorites
This example would return only 3 thumbnails, and then you can select a thumbnail like $thumbs[2] (to get the last thumbnail from the 3 returned) <?php /* @Function: YouTube Thumbnail Fetcher @Author: Dan Mcdonald. @Date: 21/05/2009 */ function get_thumbs($youtube_url){ $youtube_url = trim(str_replace(array("http://", "www."), "", strtolower($youtube_url))); if(preg_match("/youtube\.com\/watch\?v=([a-z0-9]*)/i", $youtube_url)){ preg_match_all("/http:\/\/i1\.ytimg\.com\/vi\/([A-Za-z0-9]*)\/default\.jpg/", file_get_contents("http://www.".$youtube_url), $thumbs); return array_slice($thumbs[0], 0, 3); } else { return false; } } $thumbs = get_thumbs("http://www.youtube.com/watch?v=dPdTAg_krJI"); echo $thumbs[2]; ?> PHP: This example would return all thumbnails, and then you can select a thumbnail like $thumbs[3] (to get the third thumbnail) <?php /* @Function: YouTube Thumbnail Fetcher @Author: Dan Mcdonald. @Date: 21/05/2009 */ function get_thumbs($youtube_url){ $youtube_url = trim(str_replace(array("http://", "www."), "", strtolower($youtube_url))); if(preg_match("/youtube\.com\/watch\?v=([a-z0-9]*)/i", $youtube_url)){ preg_match_all("/http:\/\/i1\.ytimg\.com\/vi\/([A-Za-z0-9]*)\/default\.jpg/", file_get_contents("http://www.".$youtube_url), $thumbs); return $thumbs[0]; } else { return false; } } $thumbs = get_thumbs("http://www.youtube.com/watch?v=dPdTAg_krJI"); echo $thumbs[3]; ?> PHP:
ah tx, Still a couple of questions: 1/ when getting thumbs for http://www.youtube.com/watch?v=dPdTAg_krJI each time i refresh the thumb is different?? (array_slice??) 2/ I will need title and description as well 3/Is it possible to get a feed based on username (i am now testing with simplepie )? Which i would use to get the thumbs? ps: did you see ufc 110 nog velasquez
hmm, still haven't found a solution i want this layout but i stuck with this .bldd.nl/youtube/ For this i am using youtube api with javascript GSvideoBar but i can't seem to find the title / description