Image thumbnails from Vimeo

1k views Asked by At

How do I insert Vimeo img thumbnails from Vimeo on my website?

snippet:

<?php
/**
 * snippet VidLister <VidLister> 
 */

$modx->getService('vidlister','VidLister',$modx->getOption('vidlister.core_path',null,$modx->getOption('core_path').'components/vidlister/').'model/vidlister/',$scriptProperties);

$modx->lexicon->load('vidlister:default');


//settings
$tpl = $modx->getOption('tpl', $scriptProperties, '{"youtube":"vlYoutube","vimeo":"vlVimeo"}');
$scripts = $modx->getOption('scripts', $scriptProperties, '1');
$sortby = $modx->getOption('sortby', $scriptProperties, 'created');
$sortdir = $modx->getOption('sortdir', $scriptProperties, 'DESC');

// 2013-03-01 ????????? ??????? ?????? topic
$topic = $_GET["topic"]?(int)$_GET["topic"]:0;


//template per source set using JSON
$tpls = $modx->fromJSON($tpl);

$where = $modx->getOption('where', $scriptProperties, '');
$where = !empty($where) ? $modx->fromJSON($where) : array();

if (!empty($topic)) $where["topic"]=$topic; // ??????? 2013-03-01

//getPage setings
$limit = $modx->getOption('limit', $scriptProperties, 10);
$offset = $modx->getOption('offset', $scriptProperties, 0);
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');

if (in_array(strtolower($sortby),array('random','rand()','rand'))) {
    $sortby = 'RAND()';
    $sortdir = '';
}

if($scripts)
{
    $modx->regClientStartupHTMLBlock('<link rel="stylesheet" type="text/css" href="/assets/components/vidlister/js/web/prettyphoto/css/prettyPhoto.css" />');
    $modx->regClientStartupScript('/assets/components/vidlister/js/web/prettyphoto/js/jquery.prettyPhoto.js');
    $modx->regClientStartupHTMLBlock('<script type="text/javascript">
        $(document).ready(function(){
            $("a[rel^=\'prettyPhoto\']").prettyPhoto({
autoplay: true,social_tools: \'\'
                                    });
        });
      </script>');
}

$output = '';

$c = $modx->newQuery('vlVideo');

//criteria 
if (!empty($where)) {
    $c->where($where);
}
$c->andCondition(array('active' => 1));

//set placeholder for getPage
$modx->setPlaceholder($totalVar, $modx->getCount('vlVideo', $c));

$c->sortby($sortby, $sortdir);
$c->limit($limit, $offset);

$idx = 0; //index
$videos = $modx->getCollection('vlVideo', $c);
foreach($videos as $video)
{
//$video2 = $video->toArray();
    $duration = $video->duration();
    $video = $video->toArray();
    // print_r($video);die;
    $source = $video['source'];
    $videoId = $video['videoId'];
    $video['duration'] = $duration;

    $filename=$modx->getOption('assets_url').'components/vidlister/images/'.$video['id'].'.jpg';
    if (!file_exists($filename)) {
    $filename="http://img.youtube.com/vi/$videoId/0.jpg";

    }

    $video['image'] = $filename;  
    $video['idx'] = $idx; //index

    if(isset($tpls[$source]))
    {
        $output .= $modx->getChunk($tpls[$source], $video);
    }
    else
    {
        $output .= $modx->getChunk($tpl, $video);
    }
    $idx++;
}

return $output;

Chunk:

<li>  <a href="http://player.vimeo.com/video/[[+videoId]]"
class="video colorbox_vimeo" rel="" title="[[+name:html]]"><img
src="[[+image]]"><alt="[[+name:html]]" /></a>
      <div class="meta">
        <span>            [[+created:date=`%d.%m.%Y`]]         
        </span>
        <span class="pull-right">
            /[[+duration.hh]]:[[+duration.mm]]:[[+duration.ss]] ([[+duration.seconds]] ???.)/
        </span> </div>
    <h4><a href="#">[[+name:html]]</a></h4> </li>
2

There are 2 answers

0
johnh10 On

This looks like copied YouTube code, yes?

$filename=$modx->getOption('assets_url').'components/vidlister/images/'.$video['id'].'.jpg';
if (!file_exists($filename)) {
$filename="http://img.youtube.com/vi/$videoId/0.jpg";

}

$video['image'] = $filename; 

I'm not going to rewrite that Vidlister library... but here's what you can do:

Use the developer API at Vimeo. Picking a video at random https://developer.vimeo.com/api/playground/videos/23895916

You'll see a JSON section for pictures

"pictures": {
    "uri": "/videos/23895916/pictures/439390000",
    "active": true,
    "sizes": [
        {
            "width": 100,
            "height": 75,
            "link": "https://i.vimeocdn.com/video/439390000_100x75.jpg"
        },
        {
            "width": 200,
            "height": 150,
            "link": "https://i.vimeocdn.com/video/439390000_200x150.jpg"
        },
        {
            "width": 295,
            "height": 166,
            "link": "https://i.vimeocdn.com/video/439390000_295x166.jpg"
        },
        {
            "width": 640,
            "height": 360,
            "link": "https://i.vimeocdn.com/video/439390000_640x360.jpg"
        },
        {
            "width": 960,
            "height": 540,
            "link": "https://i.vimeocdn.com/video/439390000_960x540.jpg"
        },
        {
            "width": 1280,
            "height": 720,
            "link": "https://i.vimeocdn.com/video/439390000_1280x720.jpg"
        }
    ]
},

So using those sizes you can copy the one(s) you want to your server.

0
Kishan Chauhan On

Just passing vimeo video url

    $link = "https://vimeo.com/23561505";
    $link = str_replace('https://vimeo.com/', 'http://vimeo.com/api/v2/video/', $link) . '.php';

    $return = unserialize(file_get_contents($link));
    print_r($return);

Here you can get all info for video title, thumb etc.

And output like:

Array
(
    [0] => Array
        (
            [id] => 23561505
            [title] => The Funny Thing About Lois
            [description] => Follow Lois (a loris) as she embarks on her first day at school. All she wants is to make friends; but this turns out to be harder than she expected. In order to set things right, she's got to embrace her unique and slightly odd qualities that others think make her so strange. <br />
My third year film made at CalArts.
            [url] => http://vimeo.com/23561505
            [upload_date] => 2011-05-10 19:48:34
            [mobile_url] => https://vimeo.com/23561505
            [thumbnail_small] => http://i.vimeocdn.com/video/153501505_100x75.jpg
            [thumbnail_medium] => http://i.vimeocdn.com/video/153501505_200x150.jpg
            [thumbnail_large] => http://i.vimeocdn.com/video/153501505_640.jpg
            [user_id] => 1976157
            [user_name] => Amelia Lorenz
            [user_url] => http://vimeo.com/amelialorenz
            [user_portrait_small] => http://i.vimeocdn.com/portrait/560459_30x30.jpg
            [user_portrait_medium] => http://i.vimeocdn.com/portrait/560459_75x75.jpg
            [user_portrait_large] => http://i.vimeocdn.com/portrait/560459_100x100.jpg
            [user_portrait_huge] => http://i.vimeocdn.com/portrait/560459_300x300.jpg
            [stats_number_of_likes] => 234
            [stats_number_of_plays] => 8604
            [stats_number_of_comments] => 20
            [duration] => 208
            [width] => 1280
            [height] => 720
            [tags] => Loris, Animation, CalArts, The Funny Thing About Lois, Lois
            [embed_privacy] => anywhere
        )

)