1

TED動画の埋め込みコードから動画のサムネイルを抜き出そうとしています。なんで?カスタム フィールドを使用してビデオを処理する WordPress テーマを使用していますが、そのフィールドのサムネイル機能は TED 用に構築されていません。再ジグしようと思います。

ビデオのサムネイル検索機能は次のとおりです (YouTube と Vimeo がカバーされています)。

function woo_get_video_image($embed) {

    $video_thumb = '';

    /* Let's start by looking for YouTube, then Vimeo */
    if ( preg_match( '/youtube/', $embed ) ) {

      // YouTube - get the video code if this is an embed code (old embed)
      preg_match( '/youtube\.com\/v\/([\w\-]+)/', $embed, $match);

      // YouTube - if old embed returned an empty ID, try capuring the ID from the new iframe embed
      if( !isset($match[1]) )
        preg_match( '/youtube\.com\/embed\/([\w\-]+)/', $embed, $match);

      // YouTube - if it is not an embed code, get the video code from the youtube URL
      if( !isset($match[1]) )
        preg_match( '/v\=(.+)&/',$embed ,$match);

      // YouTube - get the corresponding thumbnail images
      if( isset($match[1]) )
        $video_thumb = "http://img.youtube.com/vi/".$match[1]."/0.jpg";

    } else if ( preg_match( '/vimeo/', $embed ) ) {

      // Vimeo - get the video thumbnail
      preg_match( '#http://player.vimeo.com/video/([0-9]+)#s', $embed, $match );

      if ( isset($match[1]) ) {

        $video_id = $match[1];

        // Try to get a thumbnail from Vimeo
        $get_vimeo_thumb = unserialize(file_get_contents_curl('http://vimeo.com/api/v2/video/'. $video_id .'.php'));

        $video_thumb = $get_vimeo_thumb[0]['thumbnail_large'];

      }

    }

    // return whichever thumbnail image you would like to retrieve
    return $video_thumb;

 }

典型的な TED の埋め込みは次のとおりです。

<iframe    
    src="http://embed.ted.com/talks/andy_puddicombe_all_it_takes_is_10_mindful_minutes.html" 
    width="560" height="315"
    frameborder="0"
    scrolling="no"
    webkitAllowFullScreen mozallowfullscreen allowFullScreen>
</iframe>

そして、それがまったく役立つ場合は、TED API ドキュメント: http://developer.ted.com/API_Docs

preg_match および/または $get_vimeo_thumb 部分のカスタマイズに問題があるようです (少なくとも、それが起こっていると思います)。基本的に、私は PHP のこの部分を学んでいますが、でこぼこです。

4

2 に答える 2