-
-
Save vsoch/4898025919365bf23b6f to your computer and use it in GitHub Desktop.
<?php | |
header('Content-type: text/xml'); | |
/* | |
Runs from a directory containing files to provide an | |
RSS 2.0 feed that contains the list and modification times for all the | |
files. | |
*/ | |
$feedName = "My Audio Feed"; | |
$feedDesc = "Feed for the my audio files in some server folder"; | |
$feedURL = "http://www.mysite.com/audio"; | |
$feedBaseURL = "http://www.mysite.com/audio/"; // must end in trailing forward slash (/). | |
$allowed_ext = ".mp4,.MP4,.mp3,.MP3"; | |
?><<?= '?'; ?>xml version="1.0"<?= '?'; ?>> | |
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | |
<channel> | |
<title><?=$feedName?></title> | |
<link><?=$feedURL?></link> | |
<description><?=$feedDesc?></description> | |
<atom:link href="http://gogglesoptional.com/bloopers" rel="self" type="application/rss+xml" /> | |
<?php | |
$files = array(); | |
$dir=opendir("./"); | |
while(($file = readdir($dir)) !== false) | |
{ | |
$path_info = pathinfo($file); | |
$ext = strtoupper($path_info['extension']); | |
if($file !== '.' && $file !== '..' && !is_dir($file) && strpos($allowed_ext, $ext)>0) | |
{ | |
$files[]['name'] = $file; | |
$files[]['timestamp'] = filectime($file); | |
} | |
} | |
closedir($dir); | |
// natcasesort($files); - we will use dates and times to sort the list. | |
for($i=0; $i<count($files); $i++) { | |
if($files[$i] != "index.php") { | |
if (!empty($files[$i]['name'])) { | |
echo " <item>\n"; | |
echo " <title>". $files[$i]['name'] ."</title>\n"; | |
echo " <link>". $feedBaseURL . $files[$i]['name'] . "</link>\n"; | |
echo " <guid>". $feedBaseURL . $files[$i]['name'] . "</guid>\n"; | |
echo " <pubDate>". date(DATE_RSS, $files[$i]['timestamp']) ."</pubDate>\n"; | |
// echo " <pubDate>". date("D M j G:i:s T Y", $files[$i]['timestamp']) ."</pubDate>\n"; | |
// echo " <pubDate>" . $files[$i]['timestamp'] ."</pubDate>\n"; | |
echo " </item>\n"; | |
} | |
} | |
} | |
?> | |
</channel> | |
</rss> |
Sharing this here in case anyone's interested, I took some time recently to write a more comprehensive RSS feed script for audiobooks. It takes care to read the title, author, cover image and other metadata from the MP3/M4B files. I've written a blog post about it and how to get it running on a Synology NAS, and the script's at the bottom of the post. Hope that helps, and shout if you have any problems getting it running.
@kzar thanks!
I added this for my private feed hosted on traffic limited server, to not get listed by public podcast indexes:
after <channel>
echo ' <itunes:block>yes</itunes:block>' . "\n";
if you also add this, it will be refused to be added in mobile podcast apps (ios podcasts, android google podcasts), and it will only work in third party apps:
echo ' <googleplay:block>yes</googleplay:block>' . "\n";
sources: http://support.megaphone.fm/en/articles/2700280-itunes-and-google-block-tags https://support.google.com/podcast-publishers/answer/9889544?hl=en https://discussions.apple.com/thread/4871937
Oh great, glad you found it useful. Thanks for the hint about blocking the indexes, I just have my feed hosted in my local network so I haven't run into that problem! I've made a couple more improvements to the script now, so it handles M4B files as well and I have corrected a bug with the cover image logic.
How can Limit number of items?
Example: Show last 10Feed (datatime)
How can Limit number of items?
Example: Show last 10Feed (datatime)
Well, if you're using my script there's an array $book_details
that contains all the book details, that's then passed to the outputRSS
function (see the outputRSS($book_details);
line). You could just use array_slice (or similar) to shorten that array before passing it through to outputRSS
.
does anyone know of an ompl editor written in php?
I tried the script but I have some very odd thing.
The key thing is that the timestamp is always now() instead of the file timestamp.
And I don't seem to understand how the array is working. Adding something like $files[]['comment'] always returns an empty value.
Not much PHP work done the last few years so I need a reminder of somethings that might seem too silly to mention.
@hvdkooij
perhaps try my version https://gitlab.com/dewijones92/dot-files/-/blob/master/serverconfig/code/server_docker/php_files/index.php
put your files in /files
Hello! After switching from Apache to Caddy web server, I can't get rss to work. Podcast app sees files, but it always gives an error when i try to downloader the file. Is it possible that I am missing some specific part of php engine?
not tested but this might work if the cover image is always called cover.jpg: https://gist.github.com/strukturart/9a42a18c78fa44c6929bfdd3d46be0f4#file-rss-php-L23