From 369f28c93963676b00b3a366d3df073745b5d5bd Mon Sep 17 00:00:00 2001 From: Neil <neil@mckillop.org> Date: Thu, 27 Apr 2023 20:23:41 +0100 Subject: [PATCH] Initial commit --- podcast-generator.php | 125 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 podcast-generator.php diff --git a/podcast-generator.php b/podcast-generator.php new file mode 100644 index 0000000..e212d4b --- /dev/null +++ b/podcast-generator.php @@ -0,0 +1,125 @@ +<?php +// url that the mp3s will be accessed at (by the podcast client) +$url = "http://yourdomain.com/mypodcasts/"; +// path the mp3 directories are stored under +$mp3_dir = "/var/www/html/mypodcasts/"; + +/* Each mp3 directory must have an 'info.json' file in the format: + +{"author":"Peter F Hamilton","title":"The Great North Road"} + +You can add the following optional fields: +summary, owner, owneremail, subtitle, description, image_file + +If image.jpg exists in the directory, that will be used +as the podcast thumbnail (it can be overriden with +image_file above) + +*/ + +if(empty($_REQUEST['dirname'])) + die("Missing mp3 directory\n"); + +$dir_name = basename($_REQUEST['dirname']); + +if(preg_match('/[^a-z_\-0-9]/i', $dir_name)) + die("Invalid directory\n"); + +if(!empty($dir_name) and is_dir($mp3_dir.$dir_name)) { + + $path = $mp3_dir.$dir_name."/"; + $meta_file = $path."info.json"; + $files = glob($path."*.mp3"); + + if(!file_exists($meta_file)) + die("Missing info.json\n"); + + header("Content-Type: application/rss+xml; charset=utf-8"); + + $json = json_decode(file_get_contents($meta_file), true); + $author = $json['author']; + $replace_array['#AUTHOR#'] = $replace_array['#OWNER#'] = $replace_array['#OWNEREMAIL#'] = $json['author']; + $replace_array['#TITLE#'] = $json['title']; + $replace_array['#SUMMARY#'] = $replace_array['#DESCRIPTION#'] = $json['title']." by ".$json['author']; + if(isset($json['summary'])) + $replace_array['#SUMMARY#'] = $json['summary']; + $replace_array['#LINK#'] = $url.$dir_name; + $replace_array['#IMAGE_URL#'] = $url.$dir_name."/image.jpg"; + if(isset($json['image_file'])) + $replace_array['#IMAGE_URL#'] = $url.$dir_name."/".$json['image_file']; + $replace_array['#SUBTITLE#'] = ""; + if(isset($json['subtitle'])) + $replace_array['#SUBTITLE#'] = $json['subtitle']; + if(isset($json['description'])) + $replace_array['#DESCRIPTION#'] = $json['description']; + if(isset($json['owner'])) + $replace_array['#OWNER#'] = $json['owner']; + if(isset($json['owneremail'])) + $replace_array['#OWNEREMAIL#'] = $json['owneremail']; + + $number = 1; + $all_items = ""; + foreach($files as $file) { + $size = filesize($file); + $filename = basename($file); + $all_items .= " +<item> + <title>$filename</title> + <itunes:summary>$filename</itunes:summary> + <description>$filename</description> + <link>$url/$dir_name/$filename</link> + <enclosure url=\"$url/$dir_name/$filename\" type=\"audio/mpeg\" length=\"$size\"></enclosure> +"; +$all_items .= " <pubDate>".date("r", strtotime("1 June 2018 21:00 +$number days"))."</pubDate>"; +$all_items .= " + <itunes:author>$author</itunes:author> + <itunes:duration>00:32:16</itunes:duration> + <itunes:explicit>no</itunes:explicit> + <guid>$url$dir_name/$filename</guid> +</item>"; + + $number++; +} + + +} else { + http_response_code(404); + die("File not found\n"); +} + + +function header_update($buffer) { + global $replace_array; + return(str_replace(array_keys($replace_array), $replace_array, $buffer)); +} + +ob_start("header_update"); +?> +<?xml version="1.0" encoding="UTF-8"?> +<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> +<channel> +<title>#TITLE#</title> +<link>#LINK#</link> +<language>en-us</language> +<itunes:subtitle>#SUBTITLE#</itunes:subtitle> +<itunes:author>#AUTHOR#</itunes:author> +<itunes:summary>#SUMMARY#</itunes:summary> +<description>#DESCRIPTION#</description> +<itunes:owner> + <itunes:name>#OWNER#</itunes:name> + <itunes:email>#OWNEREMAIL#</itunes:email> +</itunes:owner> +<itunes:explicit>no</itunes:explicit> +<itunes:image href="#IMAGE_URL#" /> +<itunes:category text="Arts"> +<itunes:category text="Literature"/> +</itunes:category> +<?php + +ob_end_flush(); + +echo $all_items; +?> + +</channel> +</rss> -- 2.25.1