From 5d5f1fe965b43e92e7ffab25f7657f0aba7a9e88 Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 26 Sep 2019 11:00:46 +0200 Subject: [PATCH] [AutoPodcaster] FIX feeds w/o url, but w/ content --- bridges/AutoPodcasterBridge.php | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/bridges/AutoPodcasterBridge.php b/bridges/AutoPodcasterBridge.php index ac6e357d..bdd0729f 100644 --- a/bridges/AutoPodcasterBridge.php +++ b/bridges/AutoPodcasterBridge.php @@ -16,13 +16,8 @@ class AutoPodcasterBridge extends FeedExpander { strpos($formatString, 'Ogg') === 0; } - protected function parseItem($newItem){ - $item = parent::parseItem($newItem); - - $dom = getSimpleHTMLDOMCached($item['uri']); + private function extractAudio($dom) { $audios = []; - - /* 1st extraction method: by "audio" tag */ foreach($dom->find('audio') as $audioEl) { $sources = []; if($audioEl->src !== false) { @@ -35,8 +30,11 @@ class AutoPodcasterBridge extends FeedExpander { $audios[$sources[0]] = ['sources' => $sources]; } } + return $audios; + } + private function extractIframeArchive($dom) { + $audios = []; - /* 2nd extraction method: by "iframe" tag */ foreach($dom->find('iframe') as $iframeEl) { if(strpos($iframeEl->src, "https://archive.org/embed/") === 0) { $listURL = preg_replace("/\/embed\//", "/details/", $iframeEl->src, 1) . "?output=json"; @@ -59,7 +57,29 @@ class AutoPodcasterBridge extends FeedExpander { } } + return $audios; + } + protected function parseItem($newItem){ + $item = parent::parseItem($newItem); + + $dom = getSimpleHTMLDOMCached($item['uri']); + $audios = []; + if ($dom !== false) { + /* 1st extraction method: by "audio" tag */ + $audios = array_merge($audios, $this->extractAudio($dom)); + + /* 2nd extraction method: by "iframe" tag */ + $audios = array_merge($audios, $this->extractIframeArchive($dom)); + } + elseif($item['content'] !== NULL) { + /* 1st extraction method: by "audio" tag */ + $audios = array_merge($audios, $this->extractAudio(str_get_html($item['content']))); + + /* 2nd extraction method: by "iframe" tag */ + $audios = array_merge($audios, + $this->extractIframeArchive(str_get_html($item['content']))); + } if(count($audios) === 0) { return null;