获取youtube缩略图simplepie

获取youtube缩略图simplepie,youtube,simplepie,Youtube,Simplepie,因此,我试图在简单的pie中获取youtube视频的缩略图,我的问题是get_thumbnail()函数似乎没有拉它,因为get_enclosure函数似乎没有返回任何值 是否必须执行某些操作来初始化simplepie对象以正确获取附件?并非所有提要都支持/使用RSS附件它不是RSS标准的一部分,至少不是原始RSS标准。这是一种叫做。但这仍然是可以做到的。另一个问题是谷歌一直在改变,这就是YouTube的RSS提要的实际制作方式,或者你可能想用它来代替Atom提要。您可能需要查看一些文档 您必须

因此,我试图在简单的pie中获取youtube视频的缩略图,我的问题是get_thumbnail()函数似乎没有拉它,因为get_enclosure函数似乎没有返回任何值


是否必须执行某些操作来初始化simplepie对象以正确获取附件?

并非所有提要都支持/使用RSS附件它不是RSS标准的一部分,至少不是原始RSS标准。这是一种叫做。但这仍然是可以做到的。另一个问题是谷歌一直在改变,这就是YouTube的RSS提要的实际制作方式,或者你可能想用它来代替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";
}
if($enclosure=$item->get_enclosure())
{
//检查是否有缩略图。我们需要它,因为这将显示图像。
如果($thumb=$enclosure->get_thumb())
{
//添加每个项目:项目标题,链接回原始帖子,带有包含描述的工具提示。
$html.='
  • '; $html.=''; $html.='
  • '。“\n”; } } 其他的 { //有些提要不使用存储模块,但由于它们主要包含图像,因此在dsipaly范围内仍然需要这些存储模块 //Dakka Dakka和一些YouTube提要属于这一类,不确定颜色的胸部是怎么回事。。。 $htmlDOM=新的简单html dom(); $htmlDOM->load($item->get_content()); $image=$htmlDOM->find('img',0); $link=$htmlDOM->find('a',0); //添加每个项目:项目标题,链接回原始帖子,带有包含描述的工具提示。 $html.='
  • '; $html.=''; $html.='
  • '。“\n”; }

    格式似乎有点奇怪,但这是从我正在运行的代码中撕下来的。你最好还是不要从一个不支持缩略图的提要中生成很多缩略图。

    在你所有的回答中,你没有包含一条有助于用户理解的关键信息。这就是如何获得简单HTML Dom库的方法:您的示例在当前版本中也不起作用。
    new-HtmlDocument()
    是应该使用的,而不是
    new-Simple\u-HTML\u-Dom()
    您是对的,我用了将近8年的答案和代码都不起作用了。谷歌和其他许多公司已经改变了他们的API和代码库。也许我会去更新它,但它看起来越来越不可能了,因为我一直很忙。