From 1edec1aa45263fe89f78483498ee37391de55292 Mon Sep 17 00:00:00 2001 From: Corentin Garcia Date: Wed, 30 Dec 2020 19:30:02 +0100 Subject: [PATCH] [GenshinImpactBridge] Add bridge (#1912) --- bridges/GenshinImpactBridge.php | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 bridges/GenshinImpactBridge.php diff --git a/bridges/GenshinImpactBridge.php b/bridges/GenshinImpactBridge.php new file mode 100644 index 00000000..a8b13c19 --- /dev/null +++ b/bridges/GenshinImpactBridge.php @@ -0,0 +1,68 @@ + array( + 'name' => 'Category', + 'type' => 'list', + 'values' => array( + 'Latest' => 10, + 'Info' => 11, + 'Updates' => 12, + 'Events' => 13 + ), + 'defaultValue' => 10 + ) + ) + ); + + public function collectData(){ + $category = $this->getInput('category'); + + $url = 'https://genshin.mihoyo.com/content/yuanshen/getContentList'; + $url = $url . '?pageSize=3&pageNum=1&channelId=' . $category; + $api_response = getContents($url) + or returnServerError('Error while downloading the website content'); + $json_list = json_decode($api_response, true); + + foreach($json_list['data']['list'] as $json_item) { + $article_url = 'https://genshin.mihoyo.com/content/yuanshen/getContent'; + $article_url = $article_url . '?contentId=' . $json_item['contentId']; + $article_res = getContents($article_url) + or returnServerError('Error while downloading the website content'); + $article_json = json_decode($article_res, true); + + $item = array(); + + $item['title'] = $article_json['data']['title']; + $item['timestamp'] = strtotime($article_json['data']['start_time']); + $item['content'] = $article_json['data']['content']; + $item['uri'] = $this->getArticleUri($json_item); + $item['id'] = $json_item['contentId']; + + // Picture + foreach($article_json['data']['ext'] as $ext) { + if ($ext['arrtName'] == 'banner' && count($ext['value']) == 1) { + $item['enclosures'] = array($ext['value'][0]['url']); + break; + } + } + + $this->items[] = $item; + } + } + + public function getIcon() { + return 'https://genshin.mihoyo.com/favicon.ico'; + } + + private function getArticleUri($json_item) { + return 'https://genshin.mihoyo.com/en/news/detail/' . $json_item['contentId']; + } +}