[xExtension-YouTube] Stop FreshRSS from appending the enclosures again (#565)

Since FreshRSS stores the enclosures as entry attributes, it renders them
at display time: FreshRSS_Entry::content() appends the thumbnail and each
enclosure whose URL is not found in the content. The extension builds its
own content from $entry->content(), which already includes the rendered
enclosures, and replaces them with the video player (and, when "Display
the feeds content" is enabled, its own title, thumbnail and description).
None of the original URLs are part of that new content, so FreshRSS then
appended the whole enclosure again below the video: the thumbnail, a 💾
link to the old Flash URL and the description, shown twice in the second
case.

Add hidden references to the URLs of the thumbnail and of the
enclosures at the end of the generated content, so FreshRSS knows they
are already handled. This is the same approach ImageProxy uses with its
data-xextension-imageproxy-original-src attributes. The entry attributes
are left untouched, so the list thumbnail and the enclosures exposed
through the APIs do not change.

Bump the extension version to 1.4.1.

Fixes #290
This commit is contained in:
NopeCharon authored and GitHub committed 2026-10-28 08:05:35 +01:00
1 parent 85fef7a4d5
commit 0d8c8ecc1d
3 files changed
+30 -2

No files matched your search

+3
View File
@@ -23,6 +23,9 @@ With activated Youtube extension:
## Changelog
1.4.1:
- Fixed the original thumbnail, description and enclosures of the feed being appended below the video
1.4.0:
- Added an option to disable embedding videos, e.g. to only use the channel icons and URL conversion
+26 -1
View File
@@ -480,6 +480,31 @@ final class YouTubeExtension extends Minz_Extension
|| stripos($content, 'enclosure-description') !== false;
}
/**
* Returns hidden references to the URLs of the thumbnail and enclosures of an entry.
* When displaying an entry, FreshRSS appends the thumbnail and enclosures whose URL is not found in the content,
* which would show them again after the video player that replaces them.
*/
private function getEnclosureReferences(FreshRSS_Entry $entry): string {
$urls = [];
$thumbnail = $entry->thumbnail(searchEnclosures: false);
if ($thumbnail !== null) {
$urls[] = $thumbnail['url'];
}
foreach ($entry->enclosures() as $enclosure) {
$urls[] = $enclosure['url'];
}
$references = '';
foreach (array_unique($urls) as $url) {
if ($url === '') {
continue;
}
$references .= '<p hidden data-xextension-youtube-original-src="' . $url . '"></p>';
}
return $references;
}
/**
* Returns an HTML <iframe> for a given URL for the configured width and height, with content ignored, appended or formatted.
*/
@@ -553,7 +578,7 @@ final class YouTubeExtension extends Minz_Extension
}
}
return $content;
return $content . $this->getEnclosureReferences($entry);
}
/**
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "YouTube Video Feed",
"author": "Kevin Papst, Inverle",
"description": "Embed YouTube feeds inside article content.",
"version": "1.4.0",
"version": "1.4.1",
"entrypoint": "YouTube",
"type": "user"
}