douchi1945 2014-11-26 20:53
浏览 46

来自Vimeo的图像缩略图

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条回答

  • douju9272 2014-11-27 21:26
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料