0

だから私は単純なパイでYouTubeビデオのサムネイルを取得しようとしています.get_enclosure関数が値を返していないように見えるため、get_thumbnail()関数がそれを引っ張っていないように見えるという問題があります.

エンクロージャーを適切に取得するために simplepie オブジェクトを初期化するために何かしなければならないことはありますか?

4

1 に答える 1

1

すべてのフィードが RSS エンクロージャをサポート/使用しているわけではありません。これは RSS 標準の一部ではなく、少なくとも元の RSS 標準ではありません。これはMediaRSSと呼ばれるものの一部です。それでもこれはできる。もう 1 つの問題は、Google が実際に YouTube の RSS フィードを作成するGData APIを変更しているということです。Atom フィードを作成する代わりに、この APIを使用することをお勧めします。おそらくいくつかのドキュメントを見たいと思うでしょう。

一部のフィードのサムネイルを作成するには、SimplePie 以外の追加コードを使用する必要があります。必要に応じて、simple_html_dom と呼ばれるものと、thumbnail.php と呼ばれる別のスクリプトを使用してサムネイルを作成しました。MediaRSS をサポートする Flickr のようなフィードがあれば生活はより良くなりますが、強制的にサムネイルを作成する必要がある場合は、次のコードを使用しました。

if ($enclosure = $item->get_enclosure())
{
// Check to see if we have a thumbnail.  We need it because this is going to display an image.
    if ($thumb = $enclosure->get_thumbnail())
{
    // Add each item: item title, linked back to the original posting, with a tooltip containing the description.
    $html .= '<li class="' . $item_classname . '">';
    $html .= '<a href="' . $item->get_permalink() . '" title="' . $title_attr . '">'; 
    $html .= '<img src="' . $thumb . '" alt="' . $item->get_title() . '" border="0" />';
    $html .= '</a>';
    $html .= '</li>' . "\n";
}
}
else
{
// There are feeds that don't use enclosures that none the less are desireable to dsipaly wide as they contain primarily images
// Dakka Dakka and some YouTube feeds fall into this category, not sure what is up with Chest of Colors...
$htmlDOM = new simple_html_dom();
$htmlDOM->load($item->get_content());

$image = $htmlDOM->find('img', 0);
$link = $htmlDOM->find('a', 0); 

// Add each item: item title, linked back to the original posting, with a tooltip containing the description.
$html .= '<li class="' . $item_classname . '">';
$html .= '<a href="' . $link->href . '" title="' . $title_attr . '">'; 
// Sometimes I'm not getting thumbnails, so I'm going to try to make them on the fly using this tutorial:
// http://www.webgeekly.com/tutorials/php/how-to-create-an-image-thumbnail-on-the-fly-using-php/
$html .= '<img src="thumbnail.php?file=' . $image->src . '&maxw=100&maxh=150" alt="' . $item->get_title() . '" border="0" />';
$html .= '</a>';
$html .= '</li>' . "\n";
}

フォーマットは少し奇妙に思えますが、それはここで実行されている私のコードからそのまま引き出されています。サムネイルをサポートしていないフィードから大量のサムネイルを作成しないことをお勧めします。

于 2013-03-12T02:04:42.197 に答える