[HeiseBridge] fix for embedded youtube-videos (#4034)

* [HeiseBridge] fix for embbedded youtube-videos

with this the embedded youtube videos will work in the feed

* Update HeiseBridge.php

* Update HeiseBridge.php
This commit is contained in:
Tone 2024-03-28 19:42:41 +01:00 committed by GitHub
parent 0c2099a852
commit e251e358ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -160,7 +160,7 @@ class HeiseBridge extends FeedExpander
$article = defaultLinkTo($article, $item['uri']);
// remove unwanted stuff
foreach ($article->find('figure.branding, a-ad, div.ho-text, a-img, .opt-in__content-container, .a-toc__list, a-collapse') as $element) {
foreach ($article->find('figure.branding, a-ad, div.ho-text, a-img, .a-toc__list, a-collapse, .opt-in__description, .opt-in__footnote') as $element) {
$element->remove();
}
// reload html, as remove() is buggy
@ -179,6 +179,30 @@ class HeiseBridge extends FeedExpander
}
}
//fix for embbedded youtube-videos
$oldlink = '';
foreach ($article->find('div.video__yt-container') as &$ytvideo) {
if (preg_match('/www.youtube.*?\"/', $ytvideo->innertext, $link) && $link[0] != $oldlink) {
//save link to prevent duplicates
$oldlink = $link[0];
$ytiframe = <<<EOT
<iframe width="560" height="315" src="https://$link[0] title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
EOT;
//check if video is in header or article for correct possitioning
if (strpos($header->innertext, $link[0])) {
$item['content'] .= $ytiframe;
} else {
$ytvideo->innertext .= $ytiframe;
$reloadneeded = 1;
}
}
}
if (isset($reloadneeded)) {
$article = str_get_html($article->outertext);
}
$categories = $article->find('.article-footer__topics ul.topics li.topics__item a-topic a');
foreach ($categories as $category) {
$item['categories'][] = trim($category->plaintext);