RSS Generator for files on a Webserver
i wrote a php script which scans for files on a webserver and makes them available as RSS feed.
So files on webserver can be streamed to the TV over http via "Atom/RSS" section at serviio.
- Code:
<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
?>
<rss version="2.0">
<channel>
<title>Title</title>
<link>http://www.domain.com</link>
<description>Description</description>
<language>de-de</language>
<lastBuildDate><?php $now = time(); echo date(r, $now); ?></lastBuildDate>
<image>
<title>Title</title>
<url></url>
<link></link>
</image>
<?php
function ListFiles($dir)
{
if($dh = opendir($dir))
{
$files = Array();
$inner_files = Array();
while($file = readdir($dh))
{
if($file != "." && $file != ".." && $file[0] != '.')
{
if(is_dir($dir . "/" . $file))
{
$inner_files = ListFiles($dir . "/" . $file);
if(is_array($inner_files)) $files = array_merge($files, $inner_files);
}
else
{
$directLink = str_replace("/var/www/files", "http://www.domain.com/nameOfDirOnServer", $dir);
array_push($files, $directLink ."/". $file);
}
}
}
closedir($dh);
return $files;
}
}
$fileLinks = ListFiles('/var/www/files');
foreach($fileLinks as $url) {
if(preg_match("/.(avi|mkv|mp4)/",$url))
{
$filename = basename($url);
$dirname = basename(dirname($url));
$filesize = filesize("/var/www/files/".$dirname."/".$filename);
?>
<item>
<title><?php echo $filename; ?></title>
<link><?php echo $url; ?></link>
<guid><?php echo $url; ?></guid>
<description><?php echo $filename; ?></description>
<pubDate></pubDate>
<enclosure url="<?php echo $url; ?>" length="<?php echo $filesize; ?>" type="video/mp4" />
</item>
<?php
}
}
?>
</channel>
</rss>
If someone knows how to make RSS feed available with .htacces security instead of public webpages, please tell me.
I tried http://user:password@www.domain.com/files/rss.php but serviio doesnt show up the files.
Thanks.
stit