aboutsummaryrefslogtreecommitdiff
path: root/feed2podcast/feed2podcast.php
diff options
context:
space:
mode:
Diffstat (limited to 'feed2podcast/feed2podcast.php')
-rw-r--r--feed2podcast/feed2podcast.php44
1 files changed, 36 insertions, 8 deletions
diff --git a/feed2podcast/feed2podcast.php b/feed2podcast/feed2podcast.php
index 0c16481..d7f137c 100644
--- a/feed2podcast/feed2podcast.php
+++ b/feed2podcast/feed2podcast.php
@@ -64,16 +64,31 @@ foreach ($xml->channel->item as $item) {
// Only add episode to feed if media file is available
if ($content[0] != 'XXX') {
$id = md5($item->guid);
- $filename = $id.'.aac';
+ $filename = '';
+ $filetype = '';
- // Download episode if not yet done
- if (!file_exists($downloads.'/'.$filename)) {
- foreach (glob($temp.'/*') as $file) {
- if (is_file($file)) {
- unlink($file);
+ if (str_ends_with($content[1], '.mp3')) {
+ $filename = $id.'.mp3';
+ $filetype = 'audio/mpeg';
+
+ if (!file_exists($downloads.'/'.$filename)) {
+ downloadSingleMediaFile($content[1], $id, $downloads);
+ }
+
+ } else {
+ $filename = $id.'.aac';
+ $filetype = 'audio/aac';
+
+ // Download episode if not yet done
+ if (!file_exists($downloads.'/'.$filename)) {
+ foreach (glob($temp.'/*') as $file) {
+ if (is_file($file)) {
+ unlink($file);
+ }
}
+ downloadMediaFile($content[1], $id, $temp, $downloads);
}
- downloadMediaFile($content[1], $id, $temp, $downloads);
+
}
array_push($containing, $downloads.'/'.$filename);
@@ -85,7 +100,7 @@ foreach ($xml->channel->item as $item) {
echo ' <description>'.$item->description.'</description>';
echo ' <pubDate>'.$item->pubDate.'</pubDate>';
echo ' <guid>'.$item->guid.'</guid>';
- echo ' <enclosure url="https://'.$_SERVER['HTTP_HOST'].'/'.$downloads.'/'.$filename.'" length="'.filesize($downloads.'/'.$filename).'" type="audio/aac"/>';
+ echo ' <enclosure url="https://'.$_SERVER['HTTP_HOST'].'/'.$downloads.'/'.$filename.'" length="'.filesize($downloads.'/'.$filename).'" type="'.$filetype.'"/>';
echo ' <itunes:author>'.$content[0].'</itunes:author>';
echo ' <itunes:duration>'.$content[2].'</itunes:duration>';
echo '</item>';
@@ -167,6 +182,19 @@ function downloadMediaFile($url, $id, $temp, $downloads) {
}
+// Download episode media file
+function downloadSingleMediaFile($url, $id, $downloads) {
+ $outfile = fopen($downloads.'/'.$id.'.mp3', 'wb') or exit('File open failed');
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_FILE, $outfile);
+ curl_setopt($curl, CURLOPT_HEADER, 0);
+ curl_setopt($curl, CURLOPT_URL, $url);
+ curl_exec($curl);
+ curl_close($curl);
+ fclose($outfile);
+}
+
+
// Download URL and return content
function download($url) {
$curl = curl_init();