【问题标题】:Image thumbnails from Vimeo来自 Vimeo 的图像缩略图
【发布时间】:2014-11-26 20:53:37
【问题描述】:

如何将 Vimeo 中的 Vimeo img 缩略图插入到我的 网站?

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>

【问题讨论】:

    标签: php html image vimeo video-thumbnails


    【解决方案1】:

    这看起来像是复制的 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"
            }
        ]
    },
    

    因此,您可以使用这些尺寸将您想要的尺寸复制到您的服务器。

    【讨论】:

      【解决方案2】:

      只是传递 vimeo 视频网址

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

      在这里您可以获取视频标题、拇指等的所有信息。

      输出如下:

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

      【讨论】:

        猜你喜欢
        • 2018-01-07
        • 2017-10-24
        • 2015-03-18
        • 1970-01-01
        • 2013-02-04
        • 2017-10-21
        • 2013-07-26
        • 2011-10-16
        • 2013-02-21
        相关资源
        最近更新 更多