From 55bc9d3a468f74444585eb415fd3918c72d680b9 Mon Sep 17 00:00:00 2001 From: Robbt Date: Mon, 4 Feb 2019 23:45:42 -0500 Subject: [PATCH 1/3] modified podcast to search for audio enclosure if it finds a non-audio enclosure --- .../services/PodcastEpisodeService.php | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/services/PodcastEpisodeService.php b/airtime_mvc/application/services/PodcastEpisodeService.php index a607b8d08..c86503607 100644 --- a/airtime_mvc/application/services/PodcastEpisodeService.php +++ b/airtime_mvc/application/services/PodcastEpisodeService.php @@ -132,7 +132,6 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir /** @var PodcastEpisodes $episode */ foreach($episodes as $episode) { $podcast = $episode->getPodcast(); - Logging::info($episode); $this->_download($episode->getDbId(), $episode->getDbDownloadUrl(), $podcast->getDbTitle(), $this->_getAlbumOverride($podcast), $episode->getDbEpisodeTitle()); } } @@ -398,9 +397,33 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir foreach ($rss->get_items() as $item) { /** @var SimplePie_Item $item */ // If the enclosure is empty or has not URL, this isn't a podcast episode (there's no audio data) + // technically podcasts shouldn't have multiple enclosures but often CMS add non-audio files $enclosure = $item->get_enclosure(); $url = $enclosure instanceof SimplePie_Enclosure ? $enclosure->get_link() : $enclosure["link"]; - if (empty($url)) { continue; } + if (empty($url)) { + continue; + } + // next we check and see if the enclosure is not an audio file - this can happen from improperly + // formatted podcasts and we instead will search through the enclosures and see if there is an audio item + // then we pass that on, otherwise we just pass the first item since it is probably an audio file + elseif (!(substr($enclosure->get_type(), 0, 5) === 'audio')) { + // this is a rather hackish way of accessing the enclosures but get_enclosures() didnt detect multiple + // enclosures at certain points so we search through them and then manually create an enclosure object + // if we find an audio file in an enclosure and send it off + $testenclosures = $enclosures = $item->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'); + $numenclosures = sizeof($testenclosures); + for ($i = 0; $i < $numenclosures; $i++) { + $enclosure_attribs = array_values($testenclosures[$i]['attribs'])[0]; + if (stripos($enclosure_attribs['type'], 'audio') !== false) { + $url = $enclosure_attribs['url']; + $enclosure = new SimplePie_Enclosure($enclosure_attribs['url'], $enclosure_attribs['type'], $length = $enclosure_attribs['length']); + break; + } + } + } else { + $enclosure = $item->get_enclosure(); + } + //Logging::info($enclosure); $itemId = $item->get_id(); $ingested = in_array($itemId, $episodeIds) ? (empty($episodeFiles[$itemId]) ? -1 : 1) : 0; $file = $ingested > 0 && !empty($episodeFiles[$itemId]) ? @@ -420,12 +443,11 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir "author" => $this->_buildAuthorString($item), "description" => htmlspecialchars($item->get_description()), "pub_date" => $item->get_gmdate(), - "link" => $item->get_link(), - "enclosure" => $item->get_enclosure(), + "link" => $url, + "enclosure" => $enclosure, "file" => $file )); } - return $episodesArray; } From d8eeb9a0f9da6e0674de8929d5544f15c1fcce50 Mon Sep 17 00:00:00 2001 From: Robbt Date: Thu, 7 Feb 2019 23:33:48 -0500 Subject: [PATCH 2/3] did additional checking before attempting to process non-audio items as array --- .../services/PodcastEpisodeService.php | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/services/PodcastEpisodeService.php b/airtime_mvc/application/services/PodcastEpisodeService.php index c86503607..90fc214a9 100644 --- a/airtime_mvc/application/services/PodcastEpisodeService.php +++ b/airtime_mvc/application/services/PodcastEpisodeService.php @@ -410,16 +410,24 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir // this is a rather hackish way of accessing the enclosures but get_enclosures() didnt detect multiple // enclosures at certain points so we search through them and then manually create an enclosure object // if we find an audio file in an enclosure and send it off + Logging::info('found a non audio'); $testenclosures = $enclosures = $item->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'); - $numenclosures = sizeof($testenclosures); - for ($i = 0; $i < $numenclosures; $i++) { - $enclosure_attribs = array_values($testenclosures[$i]['attribs'])[0]; - if (stripos($enclosure_attribs['type'], 'audio') !== false) { - $url = $enclosure_attribs['url']; - $enclosure = new SimplePie_Enclosure($enclosure_attribs['url'], $enclosure_attribs['type'], $length = $enclosure_attribs['length']); - break; + Logging::info($testenclosures); + // we need to check if this is an array otherwise sizeof will fail and stop this whole script + if (is_array($testenclosures)) { + $numenclosures = sizeof($testenclosures); + for ($i = 0; $i < $numenclosures; $i++) { + $enclosure_attribs = array_values($testenclosures[$i]['attribs'])[0]; + if (stripos($enclosure_attribs['type'], 'audio') !== false) { + $url = $enclosure_attribs['url']; + $enclosure = new SimplePie_Enclosure($enclosure_attribs['url'], $enclosure_attribs['type'], $length = $enclosure_attribs['length']); + break; + } } } + else { + continue; + } } else { $enclosure = $item->get_enclosure(); } From a832440e0a8c1c05b06b1931b9bbac842c84a373 Mon Sep 17 00:00:00 2001 From: Robbt Date: Thu, 7 Feb 2019 23:45:45 -0500 Subject: [PATCH 3/3] added an end condition for the exit loop if it didnt succeed in finding an audio file it continues --- .../application/services/PodcastEpisodeService.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/services/PodcastEpisodeService.php b/airtime_mvc/application/services/PodcastEpisodeService.php index 90fc214a9..c6b604563 100644 --- a/airtime_mvc/application/services/PodcastEpisodeService.php +++ b/airtime_mvc/application/services/PodcastEpisodeService.php @@ -416,13 +416,19 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir // we need to check if this is an array otherwise sizeof will fail and stop this whole script if (is_array($testenclosures)) { $numenclosures = sizeof($testenclosures); - for ($i = 0; $i < $numenclosures; $i++) { + // now we loop through and look for a audio file and then stop the loop at the first one we find + for ($i = 0; $i < $numenclosures + 1; $i++) { $enclosure_attribs = array_values($testenclosures[$i]['attribs'])[0]; if (stripos($enclosure_attribs['type'], 'audio') !== false) { $url = $enclosure_attribs['url']; $enclosure = new SimplePie_Enclosure($enclosure_attribs['url'], $enclosure_attribs['type'], $length = $enclosure_attribs['length']); break; } + // if we didn't find an audio file we need to continue because there were no audio item enclosures + // so this should keep it from showing items without audio items on the episodes list + if ($i = $numenclosures) { + continue; + } } } else {