[FallGuysBridge] fix: handle new data structure (#4640)
Some checks failed
Lint / phpcs (7.4) (push) Waiting to run
Lint / phpcompatibility (7.4) (push) Waiting to run
Lint / executable_php_files_check (push) Waiting to run
Tests / phpunit8 (7.4) (push) Waiting to run
Tests / phpunit8 (8.0) (push) Waiting to run
Tests / phpunit8 (8.1) (push) Waiting to run
Tests / phpunit8 (8.2) (push) Waiting to run
Tests / phpunit8 (8.3) (push) Waiting to run
Tests / phpunit8 (8.4) (push) Waiting to run
Build Image on Commit and Release / bake (push) Waiting to run
Documentation / documentation (push) Has been cancelled

* [FallGuysBridge] fix: handle new data structure

* [FallGuysBridge] review feedback: removed mixed
This commit is contained in:
User123698745 2025-08-04 01:36:44 +02:00 committed by GitHub
parent e5f9fe6251
commit 6ec4da854f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -37,13 +37,14 @@ class FallGuysBridge extends BridgeAbstract
public function collectData() public function collectData()
{ {
$html = getSimpleHTMLDOM(self::getURI()); $newsData = self::requestJsonData(self::getURI(), false);
$data = json_decode($html->find('#__NEXT_DATA__', 0)->innertext); foreach ($newsData->props->pageProps->newsList as $newsItem) {
$newsItemUrl = self::getURI() . '/' . $newsItem->slug;
$newsItemTitle = $newsItem->header->title;
foreach ($data->props->pageProps->newsList as $newsItem) {
$headerDescription = property_exists($newsItem->header, 'description') ? $newsItem->header->description : ''; $headerDescription = property_exists($newsItem->header, 'description') ? $newsItem->header->description : '';
$headerImage = $newsItem->header->image->src; $headerImage = $newsItem->newsLandingConfig->options[0]->image->src->url;
$contentImages = [$headerImage]; $contentImages = [$headerImage];
@ -52,67 +53,79 @@ class FallGuysBridge extends BridgeAbstract
<p><img src="{$headerImage}"></p> <p><img src="{$headerImage}"></p>
HTML; HTML;
foreach ($newsItem->content->items as $contentItem) { try {
if (property_exists($contentItem, 'articleCopy')) { $newsItemData = self::requestJsonData($newsItemUrl, true);
if (property_exists($contentItem->articleCopy, 'title')) { } catch (\Exception $e) {
$title = $contentItem->articleCopy->title; $this->logger->error(sprintf('Failed to request data for news item "%s" (%s)', $newsItemTitle, $newsItemUrl), ['e' => $e]);
$newsItemData = null;
}
if (!$newsItemData) {
$this->logger->error(sprintf('Failed to parse json data for news item "%s" (%s)', $newsItemTitle, $newsItemUrl));
} else {
foreach ($newsItemData->props->pageProps->pageData->content->items as $contentItem) {
if (property_exists($contentItem, 'articleCopy')) {
if (property_exists($contentItem->articleCopy, 'title')) {
$title = $contentItem->articleCopy->title;
$content .= <<<HTML
<h2>{$title}</h2>
HTML;
}
$text = $contentItem->articleCopy->copy;
$content .= <<<HTML $content .= <<<HTML
<h2>{$title}</h2> <p>{$text}</p>
HTML; HTML;
} } elseif (property_exists($contentItem, 'articleImage')) {
$image = $contentItem->articleImage->imageSrc;
$text = $contentItem->articleCopy->copy; if ($image != $headerImage) {
$contentImages[] = $image;
$content .= <<<HTML $content .= <<<HTML
<p>{$text}</p> <p><img src="{$image}"></p>
HTML; HTML;
} elseif (property_exists($contentItem, 'articleImage')) { }
$image = $contentItem->articleImage->imageSrc; } elseif (property_exists($contentItem, 'embeddedVideo')) {
$mediaOptions = $contentItem->embeddedVideo->mediaOptions;
$mainContentOptions = $contentItem->embeddedVideo->mainContentOptions;
if ($image != $headerImage) { if (count($mediaOptions) == count($mainContentOptions)) {
$contentImages[] = $image; for ($i = 0; $i < count($mediaOptions); $i++) {
if (property_exists($mediaOptions[$i], 'youtubeVideo')) {
$videoUrl = 'https://youtu.be/' . $mediaOptions[$i]->youtubeVideo->contentId;
$image = $mainContentOptions[$i]->image->src ?? '';
$content .= <<<HTML $content .= '<p>';
<p><img src="{$image}"></p>
HTML;
}
} elseif (property_exists($contentItem, 'embeddedVideo')) {
$mediaOptions = $contentItem->embeddedVideo->mediaOptions;
$mainContentOptions = $contentItem->embeddedVideo->mainContentOptions;
if (count($mediaOptions) == count($mainContentOptions)) { if ($image != $headerImage) {
for ($i = 0; $i < count($mediaOptions); $i++) { $contentImages[] = $image;
if (property_exists($mediaOptions[$i], 'youtubeVideo')) {
$videoUrl = 'https://youtu.be/' . $mediaOptions[$i]->youtubeVideo->contentId;
$image = $mainContentOptions[$i]->image->src ?? '';
$content .= '<p>'; $content .= <<<HTML
<a href="{$videoUrl}"><img src="{$image}"></a><br>
if ($image != $headerImage) { HTML;
$contentImages[] = $image; }
$content .= <<<HTML $content .= <<<HTML
<a href="{$videoUrl}"><img src="{$image}"></a><br> <i>(Video: <a href="{$videoUrl}">{$videoUrl}</a>)</i>
HTML; HTML;
$content .= '</p>';
} }
$content .= <<<HTML
<i>(Video: <a href="{$videoUrl}">{$videoUrl}</a>)</i>
HTML;
$content .= '</p>';
} }
} }
} else {
$this->logger->warning(sprintf('Unsupported content item in news item "%s" (%s)', $newsItemTitle, $newsItemUrl));
} }
} }
} }
$item = [ $item = [
'uid' => $newsItem->_id, 'uid' => $newsItem->id,
'uri' => self::getURI() . '/' . $newsItem->_slug, 'uri' => $newsItemUrl,
'title' => $newsItem->_title, 'title' => $newsItemTitle,
'timestamp' => $newsItem->lastModified, 'timestamp' => $newsItem->activeDate,
'content' => $content, 'content' => $content,
'enclosures' => $contentImages, 'enclosures' => $contentImages,
]; ];
@ -131,4 +144,12 @@ class FallGuysBridge extends BridgeAbstract
{ {
return self::BASE_URI . '/favicon.ico'; return self::BASE_URI . '/favicon.ico';
} }
private function requestJsonData(string $url, bool $useCache)
{
$html = $useCache ? getSimpleHTMLDOMCached($url) : getSimpleHTMLDOM($url);
$jsonElement = $html->find('#__NEXT_DATA__', 0);
$json = $jsonElement ? $jsonElement->innertext : null;
return json_decode($json);
}
} }