1
0

Neu: Antenne Bayern Nachrichten Bridge

This commit is contained in:
Akamaru
2025-12-10 14:23:50 +01:00
parent 50cbd33d3f
commit 8fe8010f54
2 changed files with 192 additions and 0 deletions

183
AntenneBayernBridge.php Normal file
View File

@@ -0,0 +1,183 @@
<?php
declare(strict_types=1);
class AntenneBayernBridge extends BridgeAbstract
{
const NAME = 'Antenne Bayern Nachrichten';
const URI = 'https://www.antenne.de/';
const DESCRIPTION = 'Aktuelle Nachrichten von Antenne Bayern';
const MAINTAINER = 'Akamaru';
const CACHE_TIMEOUT = 3600; // 1 Stunde
const PARAMETERS = [
[
'category' => [
'name' => 'Kategorie',
'type' => 'list',
'required' => true,
'values' => [
'Bayern' => 'bayern',
'Deutschland' => 'deutschland',
'Welt' => 'welt',
'Sport' => 'sport',
'Stars' => 'stars',
'Eilmeldungen' => 'eilmeldungen'
]
]
]
];
public function getIcon()
{
return 'https://www.google.com/s2/favicons?domain=www.antenne.de&sz=32';
}
public function collectData()
{
$category = $this->getInput('category');
$url = 'https://www.antenne.de/nachrichten/' . $category . '/';
$html = getSimpleHTMLDOM($url);
if (!$html) {
throw new \Exception('Konnte die Antenne Bayern Nachrichten-Seite nicht laden: ' . $url);
}
// Finde alle l-cardgrid__items Container
$cardGrids = $html->find('.l-cardgrid__items');
if (empty($cardGrids)) {
throw new \Exception('Keine Artikel-Container gefunden auf der Seite');
}
// Iteriere durch alle Cardgrid-Container
foreach ($cardGrids as $cardGrid) {
// Finde alle Artikel-Items in diesem Container
$articleItems = $cardGrid->find('.l-cardgrid__item');
foreach ($articleItems as $articleItem) {
$newsItem = $articleItem->find('.c-card', 0);
if (!$newsItem) {
continue;
}
$item = [];
// Link extrahieren
$link = $newsItem->find('a.u-faux-block-link-overlay', 0);
if (!$link) {
continue;
}
$item['uri'] = $link->href;
if (strpos($item['uri'], 'http') !== 0) {
$item['uri'] = self::URI . ltrim($item['uri'], '/');
}
// Titel aus h3
$titleElement = $newsItem->find('h3.o-headline', 0);
if ($titleElement) {
$item['title'] = trim($titleElement->plaintext);
} else {
continue; // Überspringe Artikel ohne Titel
}
// Bild extrahieren
$image = $newsItem->find('figure.c-image img', 0);
$imageUrl = null;
if ($image) {
// Versuche verschiedene Bild-Attribute
if (isset($image->src) && !empty($image->src) && strpos($image->src, 'data:image') !== 0) {
$imageUrl = $image->src;
} elseif (isset($image->{'data-src'}) && !empty($image->{'data-src'})) {
$imageUrl = $image->{'data-src'};
}
if ($imageUrl) {
// Stelle sicher, dass die URL absolut ist
if (strpos($imageUrl, 'http') !== 0) {
$imageUrl = self::URI . ltrim($imageUrl, '/');
}
$item['enclosures'] = [$imageUrl];
}
}
// Beschreibung extrahieren
$description = $newsItem->find('p.c-card__text', 0);
if ($description) {
$descriptionText = trim($description->plaintext);
// Content zusammenbauen: Bild + Beschreibung
$content = '';
if ($imageUrl) {
$content .= '<img src="' . htmlspecialchars($imageUrl) . '" alt="' . htmlspecialchars($item['title']) . '"><br><br>';
}
$content .= '<p>' . htmlspecialchars($descriptionText) . '</p>';
$item['content'] = $content;
} elseif ($imageUrl) {
// Nur Bild, wenn keine Beschreibung vorhanden
$item['content'] = '<img src="' . htmlspecialchars($imageUrl) . '" alt="' . htmlspecialchars($item['title']) . '">';
} else {
$item['content'] = '';
}
// Kategorie-Flag extrahieren (optional)
$categoryFlag = $newsItem->find('small.c-image__flag', 0);
if ($categoryFlag) {
$categoryText = trim($categoryFlag->plaintext);
if (!empty($categoryText)) {
$item['categories'] = [$categoryText];
}
}
// Timestamp von der Artikelseite holen
$item['timestamp'] = $this->extractTimestamp($item['uri']);
// Autor setzen
$item['author'] = 'Antenne Bayern';
$this->items[] = $item;
// Limitiere auf 10 Artikel
if (count($this->items) >= 10) {
break 2; // Breche beide Schleifen ab
}
}
}
}
private function extractTimestamp($articleUrl)
{
try {
$articleHtml = getSimpleHTMLDOM($articleUrl);
if (!$articleHtml) {
return time(); // Fallback
}
// Suche nach dem datePublished time-Element
$timeElement = $articleHtml->find('time[itemprop="datePublished"]', 0);
if ($timeElement && isset($timeElement->datetime)) {
$datetime = $timeElement->datetime;
// Parse das Datetime-Format: "2025-12-10 13:48"
$timestamp = strtotime($datetime);
if ($timestamp !== false) {
return $timestamp;
}
}
// Fallback auf aktuelle Zeit
return time();
} catch (\Exception $e) {
// Bei Fehler: Fallback auf aktuelle Zeit
return time();
}
}
}