gpt4 book ai didi

php - 返回播放列表缩略图错误的YouTube脚本?

转载 作者:行者123 更新时间:2023-12-03 06:02:46 26 4
gpt4 key购买 nike

我在创建PHP脚本方面获得了很多帮助,该脚本基本上可以从YouTube播放列表中获取视频的最新标题和缩略图。这曾经可以工作,但是不知何故已经停止工作。有人可以帮忙吗?

php脚本在http://new.fearofmobs.com/playlist.php上运行,我已打开错误报告。该脚本不是要从YouTube播放列表返回缩略图,而是每小时对其进行缓存。编码

<?php error_reporting(E_ALL ^ E_NOTICE); ini_set('display_errors', 1);?>

<?php
$cachefile = 'videobrowser.txt';
$cache_timer = 3600 + @filemtime($cachefile);// files timestamp + 3600 seconds
if (file_exists($cachefile) && time() < $cache_timer ) {
}
else {
$data = file_get_contents("http://gdata.youtube.com/feeds/api/playlists/C82EBDAC0429B6A2?orderby=published&max-results=12");
$fh = fopen($cachefile, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
}

$thumbnail ='';
$data = simplexml_load_file($cachefile);
$xml = simplexml_load_string($data);
foreach($xml->entry as $playlist){
$media = $playlist->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->thumbnail[1]->attributes();
$thumb = $attrs['url'];
$attrs = $media->group->player->attributes();
$video = $attrs['url'];
$title = substr( $media->group->title, 21);
$url = $video;
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
$vid_Id = $my_array_of_vars['v'];

###################NEW CODE
$toggle = 'hotlink';// replace 'hotlink' with 'null' to save images locally
if ($toggle == 'hotlink'){
$image_ID = $thumb; // hotlink images from YouTube
}
else{
///////////////////////////////// Save Images To Local Webserver
///////////////////////////////// just in case Youtube objects to hotlinking

$image_ID = $vid_Id.".jpg"; /// or use sub folder for neatness -> "images_folder/".$vid_Id.".jpg"
$image_saved = @filemtime($image_ID);// @ is used to suppress the error caused by the image not having been seen before
if (!$image_saved){/// if you can't find it on local server go fetch it and save to the sites server
file_put_contents($image_ID, file_get_contents($thumb));

//// you can delete the line below
echo ' fecthed image >> '.$image_ID."<br>" ;
//// you can delete the line above

}//// close if image saved
} ##################### END NEW CODE

$thumbnail .= '<div style="float:left; cursor:pointer;">
<p class="crop"><a class="videobox various iframe" href="http://www.youtube.com/embed/' . $vid_Id . '?autoplay=1&amp;hd=1" onclick=swapper('. $vid_Id .')><img src="' .$image_ID . '" title="' . $title . '" width="74" height="56"/></a></p></div>';
}
?>

<?php echo $thumbnail; ?>

错误
Warning: simplexml_load_file(): videobrowser.txt:1: parser error : Document is empty in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file(): in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file(): ^ in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file(): videobrowser.txt:1: parser error : Start tag expected, '<' not found in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file(): in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: simplexml_load_file(): ^ in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 16
Warning: Invalid argument supplied for foreach() in /hermes/waloraweb095/b2598/moo.fearofmobscom/fearofmobs2/playlist.php on line 18

如果有人需要进一步的信息,请告诉我。

最佳答案

据我所知,您没有输入填充elsevideobrowser.txt子句:

if (file_exists($cachefile) && time() < $cache_timer ) {
// you are going here
}
else {
// but you should be going here
$data = file_get_contents("http://gdata.youtube.com/feeds/api/playlists/C82EBDAC0429B6A2?orderby=published&max-results=12");
$fh = fopen($cachefile, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
}

我猜测某个时候 videobrowser.txt的创建没有任何内容(一个完全空的文件)。这意味着您不会重新填充文件,而是期望它会被填充。

检查并查看 videobrowser.txt是否存在,如果存在,则将其删除。

关于php - 返回播放列表缩略图错误的YouTube脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11852706/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com