diff --git a/README.md b/README.md index 6a476c6..16f8f1e 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,13 @@ Diese Sammlung enthält verschiedene Bridge-Implementierungen für RSS-Bridge, u ### [Punishing: Gray Raven News Bridge](https://bridge.ponywave.de/#bridge-PunishingGrayRavenNewsBridge) (Von Akamaru) - **Beschreibung**: Zeigt die neuesten Nachrichten von Punishing: Gray Raven +### [Radio Gong Würzburg News Bridge](https://bridge.ponywave.de/#bridge-RadioGongWuerzburgBridge) (Von Akamaru) +- **Beschreibung**: Aktuelle Nachrichten von Radio Gong Würzburg +- **Hinweise**: + - Zeigt bis zu 20 aktuelle News-Artikel + - Enthält Titel, Datum, Kategorie (z.B. "Lokales") und Bilder + - Zeitstempel werden aus dem deutschen Datumsformat extrahiert + ### [RSS Filter Bridge](https://bridge.ponywave.de/#bridge-RSSFilterBridge) (Von Akamaru) - **Beschreibung**: Filtert und modifiziert Elemente aus beliebigen RSS/Atom-Feeds - **Parameter**: diff --git a/RadioGongWuerzburgBridge.php b/RadioGongWuerzburgBridge.php new file mode 100644 index 0000000..8874f4c --- /dev/null +++ b/RadioGongWuerzburgBridge.php @@ -0,0 +1,122 @@ +find('.teaser-list-item'); + + if (empty($newsItems)) { + throw new \Exception('Keine News-Artikel gefunden auf der Seite'); + } + + foreach ($newsItems as $newsItem) { + $item = []; + + // Link und Titel extrahieren + $link = $newsItem->find('a', 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', 0); + if ($titleElement) { + $item['title'] = trim($titleElement->plaintext); + } else { + continue; // Überspringe Artikel ohne Titel + } + + // Caption mit Datum und Kategorie extrahieren + // Format: "30.11.2025, 19:17 Uhr in Lokales" + $caption = $newsItem->find('.caption', 0); + if ($caption) { + $captionText = trim($caption->plaintext); + + // Datum extrahieren (DD.MM.YYYY, HH:MM Uhr) + if (preg_match('/(\d{2})\.(\d{2})\.(\d{4}),\s+(\d{2}):(\d{2})\s+Uhr/', $captionText, $matches)) { + $day = $matches[1]; + $month = $matches[2]; + $year = $matches[3]; + $hour = $matches[4]; + $minute = $matches[5]; + + // Erstelle Timestamp + $item['timestamp'] = strtotime("$year-$month-$day $hour:$minute:00"); + } + + // Kategorie extrahieren (Text nach "in ") + if (preg_match('/in\s+(.+)$/i', $captionText, $categoryMatch)) { + $item['categories'] = [trim($categoryMatch[1])]; + } + } + + // Bild extrahieren + $image = $newsItem->find('img', 0); + if ($image) { + // Verwende data-srcset falls vorhanden, sonst src + $imageUrl = null; + + if (isset($image->{'data-srcset'}) && !empty($image->{'data-srcset'})) { + // Nimm das erste Bild aus dem srcset + $srcset = $image->{'data-srcset'}; + if (preg_match('/^(https?:\/\/[^\s]+)/', $srcset, $imageMatch)) { + $imageUrl = $imageMatch[1]; + } + } elseif (isset($image->src) && !empty($image->src) && strpos($image->src, 'data:image') !== 0) { + // Nur normale URLs verwenden, keine base64-codierten Bilder + $imageUrl = $image->src; + } + + if ($imageUrl) { + // Bereinige die URL (entferne .webp falls vorhanden und nimm die jpg-Variante) + $imageUrl = str_replace('.webp', '', $imageUrl); + + $item['enclosures'] = [$imageUrl]; + $item['content'] = '' . htmlspecialchars($item['title']) . ''; + } + } + + // Fallback für Timestamp + if (!isset($item['timestamp'])) { + $item['timestamp'] = time(); + } + + // Autor setzen + $item['author'] = 'Radio Gong Würzburg'; + + $this->items[] = $item; + + // Limitiere auf 20 Artikel + if (count($this->items) >= 20) { + break; + } + } + } +}