Skip to content

Instantly share code, notes, and snippets.

@phpfunk
Last active October 21, 2015 14:23
Show Gist options
  • Save phpfunk/2636217 to your computer and use it in GitHub Desktop.
Save phpfunk/2636217 to your computer and use it in GitHub Desktop.
Viddler - Get thumbnails example
<?
include '/path/to/viddler/api/';
$v = new Viddler_V2('API_KEY');
$auth = $v->viddler_users_auth(array(
'user' => 'YOUR USERNAME',
'password' => 'YOUR PASSWORD'
));
if (! isset($auth['auth']['sessionid'])) {
//Handle auth error
}
//Get Thumbnails
$video = $v->viddler_videos_getDetails(array(
'sessionid' => $auth['auth']['sessionid'],
'video_id' => 'VIDEO_ID'
));
//Original Thumb and Total Thumbs
$org_thumb = $video['video']['thumbnail_url'];
$total_thumbs = $video['video']['thumbnails_count'];
//Looping and show medium thumb version of each
for ($i = 0; $i < $total_thumbs; $i++) {
//Replace _2_ with _1_ to get medium thumb rather than large
$tmp_thumb = str_replace('_2_', '_1_', $org_thumb);
//Regex to replace _v# with current thumb
$tmp_thumb = preg_replace('/(.*?)(_v[0-9])(\..*?)/', "$1_$i$3", $tmp_thumb);
//Display it
echo '<img src="' . $tmp_thumb . '" width="114" height="86" border="0" />';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment