From 6b83bf25fdd4f66b6be1528634ee037f4f00451f Mon Sep 17 00:00:00 2001 From: John S Long Date: Sun, 2 Oct 2022 12:38:33 -0500 Subject: [PATCH] [RoosterTeethBridge] Add episode description, optional episode image (#3080) --- bridges/RoosterTeethBridge.php | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/bridges/RoosterTeethBridge.php b/bridges/RoosterTeethBridge.php index 797cd96e..21bac4fe 100644 --- a/bridges/RoosterTeethBridge.php +++ b/bridges/RoosterTeethBridge.php @@ -51,6 +51,12 @@ class RoosterTeethBridge extends BridgeAbstract 'False' => false ] ], + 'episodeImage' => [ + 'name' => 'Episode Image', + 'type' => 'checkbox', + 'defaultValue' => 'checked', + 'title' => 'Select whether to include an episode image (if available)', + ], 'limit' => [ 'name' => 'Limit', 'type' => 'number', @@ -104,8 +110,38 @@ class RoosterTeethBridge extends BridgeAbstract $item['title'] = $value['attributes']['title']; $item['timestamp'] = $value['attributes']['member_golive_at']; $item['author'] = $value['attributes']['show_title']; + $item['content'] = $this->getItemContent($value); $this->items[] = $item; } } + + protected function getItemContent(array $value): string + { + $content = nl2br($value['attributes']['description']); + + if (isset($value['attributes']['length'])) { + $duration_format = $value['attributes']['length'] > 3600 ? 'G:i:s' : 'i:s'; + $content = sprintf( + 'Duration: %s

%s', + gmdate($duration_format, $value['attributes']['length']), + $content + ); + } + + if ($this->getInput('episodeImage') === true) { + foreach ($value['included']['images'] ?? [] as $image) { + if ($image['type'] == 'episode_image') { + $content = sprintf( + '

%s', + $image['attributes']['medium'], + $content, + ); + break; + } + } + } + + return $content; + } }