Skip to content

Instantly share code, notes, and snippets.

@shibatch
Forked from vsoch/index.php
Last active February 23, 2020 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibatch/24bebab16d908ae92a77bce5f187cd19 to your computer and use it in GitHub Desktop.
Save shibatch/24bebab16d908ae92a77bce5f187cd19 to your computer and use it in GitHub Desktop.
Unlike the original script, the generated RSS feed can be used for podcasting. This script generates RSS feed for files in a directory folder. Put this file in a folder with files, modify the $allowed_ext variable to customize your extensions, and $feedName, $feedDesc, $feedURL, and $feedBaseURL. Then navigate to the folder on the web to see the…
<?php
header('Content-type: text/xml');
/*
Based on https://gist.github.com/vsoch/4898025919365bf23b6f
The generated feed can be used for podcasting.
Runs from a directory containing files to provide an
RSS feed that contains the list and modification times for all the
files.
*/
$feedBaseURL = "https://example.com/podcast/";
$feedName = "My Podcast";
$feedDesc = "Feed for the my audio files in some server folder";
$feedURL = $feedBaseURL . "index.php";
$allowed_ext = ".mp4,.MP4,.mp3,.MP3";
?><<?= '?'; ?>xml version="1.0"<?= '?'; ?>>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title><?=$feedName?></title>
<link><?=$feedURL?></link>
<language>en-us</language>
<itunes:subtitle>Subtitle</itunes:subtitle>
<itunes:author>Author</itunes:author>
<itunes:summary>Description</itunes:summary>
<description><?=$feedDesc?></description>
<itunes:owner>
<itunes:name>Owner Name</itunes:name>
<itunes:email>me@example.com</itunes:email>
</itunes:owner>
<itunes:image href="<?=$feedBaseURL?>artwork.jpg"/>
<itunes:category text="Health">
</itunes:category>
<itunes:explicit>no</itunes:explicit>
<itunes:block>Yes</itunes:block>
<?php
$files = array();
$dir=opendir("./");
$i = 0;
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[$i][0] = $file;
$files[$i][1] = filectime($file);
$files[$i][2] = filesize($file);
$i++;
}
}
closedir($dir);
for($i=0; $i<count($files); $i++) {
if($files[$i][0] != "index.php") {
if (!empty($files[$i][0])) {
echo "<item>\n";
echo " <title>". $files[$i][0] ."</title>\n";
echo " <itunes:author>Author</itunes:author>\n";
echo " <itunes:subtitle>Subtitle</itunes:subtitle>\n";
echo " <itunes:summary>Summary</itunes:summary>\n";
echo " <itunes:image href=\"" . $feedBaseURL . "artwork.jpg\"></itunes:image>\n";
echo " <enclosure url=\"". $feedBaseURL . $files[$i][0] . "\" type=\"audio/mpeg\" length=\"" . $files[$i][2] . "\"/>\n";
echo " <guid>". $feedBaseURL . $files[$i][0] . "</guid>\n";
echo " <pubDate>". date(DATE_RSS, $files[$i][1]) ."</pubDate>\n";
echo " <itunes:duration>01:00:00</itunes:duration>\n";
echo " <itunes:explicit>no</itunes:explicit>\n";
echo "</item>\n";
}
}
}
?>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment