私は、基本的にYouTubeプレイリストからビデオの最新のタイトルとサムネイルを取得するPHPスクリプトの作成に多くの助けを借りてきました。これは以前は機能していましたが、どういうわけか機能しなくなりました。誰か助けてもらえますか?
phpスクリプトはhttp://new.fearofmobs.com/playlist.phpで実行されており、エラー報告をオンにしています。このスクリプトは、YouTubeプレイリストからサムネイルを返し、1時間ごとにキャッシュすることを意図したものではありません。コード
<?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&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
さらに詳しい情報が必要な場合はお知らせください。