[RoosterTeethBridge] Add episode description, optional episode image (#3080)

This commit is contained in:
John S Long 2022-10-02 12:38:33 -05:00 committed by GitHub
parent 30d964b356
commit 6b83bf25fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 0 deletions

View File

@ -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<br><br>%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(
'<img src="%s"/><br><br>%s',
$image['attributes']['medium'],
$content,
);
break;
}
}
}
return $content;
}
}