diff --git a/README.md b/README.md index 44df096..ecbc9dc 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,14 @@ Diese Sammlung enthält verschiedene Bridge-Implementierungen für RSS-Bridge, u ### WHO Disease Outbreak Bridge (Von Brawl) - **Beschreibung**: Neueste WHO Disease Outbreak News (DONs) mit Informationen über bestätigte akute Ereignisse im öffentlichen Gesundheitswesen oder potenzielle Ereignisse von Interesse +### Wuthering Waves News Bridge (Von Akamaru) +- **Beschreibung**: Zeigt die neuesten Nachrichten von Wuthering Waves +- **Parameter**: + - **Sprache**: Wähle zwischen English, Deutsch, Japanese, Korean, Traditional Chinese, Spanish, French (Standard: English) +- **Hinweise**: + - Automatische Deduplizierung von Artikeln + - Limitiert auf die 10 neuesten Artikel + ### Y2Mate Downloader Changelog Bridge (Von Akamaru) - **Beschreibung**: Changelog für Y2Mate Downloader - **Parameter**: diff --git a/WutheringWavesNewsBridge.php b/WutheringWavesNewsBridge.php new file mode 100644 index 0000000..281ffed --- /dev/null +++ b/WutheringWavesNewsBridge.php @@ -0,0 +1,136 @@ + [ + 'name' => 'Language', + 'type' => 'list', + 'values' => [ + 'English' => 'en', + 'Deutsch' => 'de', + 'Japanese' => 'jp', + 'Korean' => 'kr', + 'Traditional Chinese' => 'zh-tw', + 'Spanish' => 'es', + 'French' => 'fr' + ], + 'defaultValue' => 'en' + ] + ] + ]; + + private $apiBaseUrl = 'https://hw-media-cdn-mingchao.kurogame.com/akiwebsite/website2.0/json/G152'; + + public function collectData() + { + $language = $this->getInput('language'); + + // Fetch the main menu JSON to get the article list + $menuUrl = $this->apiBaseUrl . '/' . $language . '/MainMenu.json'; + $menuJson = getContents($menuUrl); + $menuData = json_decode($menuJson, true); + + if (!isset($menuData['article']) || !is_array($menuData['article'])) { + returnServerError('Could not find article array in MainMenu.json'); + } + + // Deduplicate articles by articleId + $uniqueArticles = []; + foreach ($menuData['article'] as $article) { + $articleId = $article['articleId']; + + // Keep the article with the highest sortingMark if duplicates exist + if (!isset($uniqueArticles[$articleId]) || + $article['sortingMark'] > $uniqueArticles[$articleId]['sortingMark']) { + $uniqueArticles[$articleId] = $article; + } + } + + // Sort by sortingMark (descending - higher is newer) + usort($uniqueArticles, function ($a, $b) { + return $b['sortingMark'] - $a['sortingMark']; + }); + + // Limit to 10 most recent articles + $uniqueArticles = array_slice($uniqueArticles, 0, 10); + + // Fetch detailed information for each article + foreach ($uniqueArticles as $articleMeta) { + $articleId = $articleMeta['articleId']; + + // Fetch the detailed article JSON + $articleUrl = $this->apiBaseUrl . '/' . $language . '/article/' . $articleId . '.json'; + + try { + $articleJson = getContents($articleUrl); + $articleData = json_decode($articleJson, true); + + if (!$articleData) { + continue; // Skip if article data is invalid + } + + $item = []; + + // Title + $item['title'] = $articleData['articleTitle'] ?? $articleMeta['articleTitle']; + + // Content (HTML is already provided in the API) + $item['content'] = $articleData['articleContent'] ?? ''; + + // URI - construct a link to the news page + $item['uri'] = self::URI . '/' . $articleId; + + // Timestamp - use createTime or startTime from the main menu data + if (isset($articleMeta['createTime'])) { + $item['timestamp'] = strtotime($articleMeta['createTime']); + } elseif (isset($articleMeta['startTime'])) { + $item['timestamp'] = strtotime($articleMeta['startTime']); + } + + // Categories + if (isset($articleData['articleTypeName'])) { + $item['categories'] = [$articleData['articleTypeName']]; + } + + // Author + $item['author'] = 'Kuro Games'; + + // UID + $item['uid'] = 'wuthering-waves-' . $articleId; + + $this->items[] = $item; + + } catch (Exception $e) { + // Skip articles that fail to load + continue; + } + } + } + + public function getName() + { + $language = $this->getInput('language'); + if ($language) { + $languageNames = [ + 'en' => 'English', + 'de' => 'Deutsch', + 'jp' => 'Japanese', + 'kr' => 'Korean', + 'zh-tw' => 'Traditional Chinese', + 'es' => 'Spanish', + 'fr' => 'French' + ]; + return self::NAME . ' (' . ($languageNames[$language] ?? $language) . ')'; + } + return self::NAME; + } +}