Created
April 10, 2012 04:47
-
-
Save codemaker38/2348368 to your computer and use it in GitHub Desktop.
Video: Thumbnail for Youtube and Vimeo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# get video info | |
$video_photo = base_url() .'images/profiles/no-thumb.jpg'; | |
preg_match('/http:\/\/vimeo.com\/(\d+)$/', $video['link'], $vimeo); | |
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video['link'], $youtube); | |
if(count($vimeo) > 0) { | |
$vimeo_id = $vimeo[1]; | |
$vimeo_photo = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vimeo_id.php")); | |
$video_photo = $vimeo_photo[0]['thumbnail_small']; | |
} | |
if(count($youtube) > 0) { | |
$video_id = $youtube[1]; | |
$video_photo = 'http://img.youtube.com/vi/' . $video_id . '/' . rand(1, 3) . '.jpg'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment