RSS thumbnails (#5972)

* Added addtional media:content for thumbnails

* Fix whitespace

* More attributes for enclosures

* Fix variable

* Fix variable

* No duplicates

---------

Co-authored-by: root <root@ha-server.lan>
This commit is contained in:
Alexandre Alapetiteandroot authored and GitHub committed 2024-02-26 09:00:35 +01:00
1 parent 84d88d4b5d
commit 25166c218b
2 files changed
+24 -14

No files matched your search

+1 -1
View File
@@ -314,7 +314,7 @@ HTML;
}
/**
* @return array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string,'height'?:int,'width'?:int,'thumbnails'?:array<string>}|null
* @return array{'url':string,'height'?:int,'width'?:int,'time'?:string}|null
*/
public function thumbnail(bool $searchEnclosures = true): ?array {
$thumbnail = $this->attributeArray('thumbnail') ?? [];
+23 -13
View File
@@ -41,28 +41,38 @@ foreach ($this->entries as $item) {
echo "\t\t\t", '<category>', $category, '</category>', "\n";
}
}
$enclosures = iterator_to_array($item->enclosures(false));
$thumbnail = $item->thumbnail(false);
if (!empty($thumbnail['url'])) {
// https://www.rssboard.org/media-rss#media-thumbnails
echo "\t\t\t", '<media:thumbnail url="' . $thumbnail['url']
. (empty($thumbnail['width']) ? '' : '" width="' . $thumbnail['width'])
. (empty($thumbnail['height']) ? '' : '" height="' . $thumbnail['height'])
. (empty($thumbnail['type']) ? '' : '" type="' . $thumbnail['type'])
. (empty($thumbnail['time']) ? '' : '" time="' . $thumbnail['time'])
. '" />', "\n";
// Mostly for MailChimp + Feedbro which do not support <media:thumbnail> https://mailchimp.com/help/rss-merge-tags/
$thumbnail['medium'] ??= 'image';
array_unshift($enclosures, $thumbnail);
}
$enclosures = $item->enclosures(false);
if (is_iterable($enclosures)) {
foreach ($enclosures as $enclosure) {
// https://www.rssboard.org/media-rss
echo "\t\t\t", '<media:content url="' . $enclosure['url']
. (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium'])
. (empty($enclosure['type']) ? '' : '" type="' . $enclosure['type'])
. (empty($enclosure['length']) ? '' : '" length="' . $enclosure['length'])
. '">'
. (empty($enclosure['title']) ? '' : '<media:title type="html">' . $enclosure['title'] . '</media:title>')
. (empty($enclosure['credit']) ? '' : '<media:credit>' . $enclosure['credit'] . '</media:credit>')
. '</media:content>', "\n";
$urls = [];
foreach ($enclosures as $enclosure) {
if (empty($enclosure['url']) || isset($urls[$enclosure['url']])) {
continue;
}
$urls[$enclosure['url']] = true;
// https://www.rssboard.org/media-rss
echo "\t\t\t", '<media:content url="' . $enclosure['url']
. (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium'])
. (empty($enclosure['type']) ? '' : '" type="' . $enclosure['type'])
. (empty($enclosure['length']) ? '' : '" length="' . $enclosure['length'])
. (empty($enclosure['height']) ? '' : '" height="' . $enclosure['height'])
. (empty($enclosure['width']) ? '' : '" width="' . $enclosure['width'])
. '">'
. (empty($enclosure['title']) ? '' : '<media:title type="html">' . $enclosure['title'] . '</media:title>')
. (empty($enclosure['credit']) ? '' : '<media:credit>' . $enclosure['credit'] . '</media:credit>')
. '</media:content>', "\n";
}
?>
<description><![CDATA[<?php