-->

获取YouTube缩略图了SimplePie(Get youtube thumbnail simpl

2019-07-21 05:54发布

所以我试图让简单的馅饼YouTube视频的缩略图,我的问题是,get_thumbnail()函数似乎并没有被拉动,因为get_enclosure功能似乎没有返回值。

有什么必须做初始化对象了SimplePie正确获取机箱?

Answer 1:

并非所有的饲料支持/使用RSS附件它不是RSS标准的一部分,至少不是原来的RSS标准。 它是一种叫做一部分MediaRSS中 。 尽管如此可以做到这一点。 另一个问题是谷歌一直在不断变化的GData API这就是实际上使得YouTube的RSS源或这样做,你可能想使用这个API ,而不是产生Atom提要。 你可能想看看一些文档。

你必须使用超出了SimplePie额外的代码来创建缩略图一些饲料,我用一种叫simple_html_dom并呼吁thumbnail.php使缩略图根据需要另一个脚本。 你的生活是更好,如果你有一个像Flickr的饲料,它支持MediaRSS的,但如果你必须强制缩略图的创作,我用这个代码:

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";
}

格式化似乎有点奇怪,但这是从一个运行我的代码的权利撕开这里 。 你还是最好关闭没有从不支持他们进作出了很多的缩略图。



文章来源: Get youtube thumbnail simplepie