From 54521ffe7c9ee9c42eb974552dd91a94b517dca2 Mon Sep 17 00:00:00 2001 From: Thorsten Ortlepp Date: Fri, 14 May 2021 14:35:43 +0200 Subject: Fix for MP3 files in feed --- feed2podcast/feed2podcast.php | 44 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'feed2podcast/feed2podcast.php') 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 ' '.$item->description.''; echo ' '.$item->pubDate.''; echo ' '.$item->guid.''; - echo ' '; + echo ' '; echo ' '.$content[0].''; echo ' '.$content[2].''; echo ''; @@ -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(); -- cgit v1.2.3