0

Vimeo の Vimeo img サムネイルを自分の Web サイトに挿入するにはどうすればよいですか?

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;

かたまり:

<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>
4

2 に答える 2

0

これは YouTube のコードをコピーしたように見えますね。

$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; 

その Vidlister ライブラリを書き直すつもりはありませんが、できることは次のとおりです。

Vimeo で開発者 API を使用します。無作為に動画を選ぶ https://developer.vimeo.com/api/playground/videos/23895916

写真の JSON セクションが表示されます。

"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"
        }
    ]
},

したがって、これらのサイズを使用して、必要なサイズをサーバーにコピーできます。

于 2014-11-27T21:26:39.287 に答える