From fe59cbabc950046ead7a8342e76e7a42ab1de28a Mon Sep 17 00:00:00 2001 From: MarKoeh <75181140+Mar-Koeh@users.noreply.github.com> Date: Fri, 4 Nov 2022 19:03:12 +0100 Subject: [PATCH] [ARDAudiothekBridge] added bridge ARDAudiothek.de (#3132) * [ARDAudiothekBridge] added bridge ARDAudiothek.de ARD, the union of Germany's regional public-service broadcasters, operates a video and an audio streaming service. The video streaming service is ARDMediathek, for which a bridge already exists. The audio streaming service is ARDAudiothek. This commit adds initial support for ARDAudiothek. It currently supports turning shows to feeds. * [ARDAudiothekBridge] fixed code style Sorry. Forgot spaces surrounding the concatenation symbol --- bridges/ARDAudiothekBridge.php | 150 +++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 bridges/ARDAudiothekBridge.php diff --git a/bridges/ARDAudiothekBridge.php b/bridges/ARDAudiothekBridge.php new file mode 100644 index 00000000..3ec84d23 --- /dev/null +++ b/bridges/ARDAudiothekBridge.php @@ -0,0 +1,150 @@ + [ + 'name' => 'Show Link or ID', + 'required' => true, + 'title' => 'Link to the show page or just its numeric suffix', + 'defaultValue' => 'https://www.ardaudiothek.de/sendung/kalk-welk/10777871/' + ], + 'limit' => self::LIMIT, + ] + ]; + + + /** + * Holds the title of the current show + * + * @var string + */ + private $title; + + /** + * Holds the URI of the show + * + * @var string + */ + private $uri; + + /** + * Holds the icon of the feed + * + */ + private $icon; + + public function collectData() + { + $oldTz = date_default_timezone_get(); + + date_default_timezone_set('Europe/Berlin'); + + $pathComponents = explode('/', $this->getInput('path')); + if (empty($pathComponents)) { + returnClientError('Path may not be empty'); + } + if (count($pathComponents) < 2) { + $showID = $pathComponents[0]; + } else { + $lastKey = count($pathComponents) - 1; + $showID = $pathComponents[$lastKey]; + if (strlen($showID) === 0) { + $showID = $pathComponents[$lastKey - 1]; + } + } + + $url = self::APIENDPOINT . 'programsets/' . $showID . '/'; + $rawJSON = getContents($url); + $processedJSON = json_decode($rawJSON)->data->programSet; + + $limit = $this->getInput('limit'); + $answerLength = 1; + $offset = 0; + $numberOfElements = 1; + + while ($answerLength != 0 && $offset < $numberOfElements && (is_null($limit) || $offset < $limit)) { + $rawJSON = getContents($url . '?offset=' . $offset); + $processedJSON = json_decode($rawJSON)->data->programSet; + + $answerLength = count($processedJSON->items->nodes); + $offset = $offset + $answerLength; + $numberOfElements = $processedJSON->numberOfElements; + + foreach ($processedJSON->items->nodes as $audio) { + $item = []; + $item['uri'] = $audio->sharingUrl; + $item['title'] = $audio->title; + $imageSquare = str_replace(self::IMAGEWIDTHPLACEHOLDER, self::IMAGEWIDTH, $audio->image->url1X1); + $image = str_replace(self::IMAGEWIDTHPLACEHOLDER, self::IMAGEWIDTH, $audio->image->url); + $item['enclosures'] = [ + $audio->audios[0]->url, + $imageSquare + ]; + // synopsis in list is shortened, full synopsis is available using one request per item + $item['content'] = '

' . $audio->synopsis . '

'; + $item['timestamp'] = $audio->publicationStartDateAndTime; + $item['uid'] = $audio->id; + $item['author'] = $audio->programSet->publicationService->title; + $item['categories'] = [ $audio->programSet->editorialCategories->title ]; + $this->items[] = $item; + } + } + $this->title = $processedJSON->title; + $this->uri = $processedJSON->sharingUrl; + $this->icon = str_replace(self::IMAGEWIDTHPLACEHOLDER, self::IMAGEWIDTH, $processedJSON->image->url1X1); + + $this->items = array_slice($this->items, 0, $limit); + + date_default_timezone_set($oldTz); + } + + /** {@inheritdoc} */ + public function getURI() + { + if (!empty($this->uri)) { + return $this->uri; + } + return parent::getURI(); + } + + /** {@inheritdoc} */ + public function getName() + { + if (!empty($this->title)) { + return $this->title; + } + return parent::getName(); + } + + /** {@inheritdoc} */ + public function getIcon() + { + if (!empty($this->icon)) { + return $this->icon; + } + return parent::getIcon(); + } +}