diff --git a/docs/en/game.md b/docs/en/game.md index 66a24c264..ff0137c3f 100755 --- a/docs/en/game.md +++ b/docs/en/game.md @@ -337,3 +337,15 @@ News data from https://warthunder.com/en/news/ The year, month and day provided under UTC time zone are the same as the official website, so please ignore the specific time!!! + +## ファミ通 + +### Category + + + +| 新着 | PS5 | Switch | PS4 | ニュース | ゲームニュース | PR TIMES | 動画 | 特集・企画記事 | インタビュー | 取材・リポート | レビュー | インディーゲーム | +| ----------- | --- | ------ | --- | ---- | --------- | -------- | ------ | --------------- | --------- | ------------ | ------ | ---------- | +| new-article | ps5 | switch | ps4 | news | news-game | prtimes | videos | special-article | interview | event-report | review | indie-game | + + diff --git a/docs/game.md b/docs/game.md index fd2dcbb8c..bebe6070a 100644 --- a/docs/game.md +++ b/docs/game.md @@ -967,6 +967,18 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` +## ファミ通 + +### 分类 + + + +| 新着 | PS5 | Switch | PS4 | ニュース | ゲームニュース | PR TIMES | 動画 | 特集・企画記事 | インタビュー | 取材・リポート | レビュー | インディーゲーム | +| ----------- | --- | ------ | --- | ---- | --------- | -------- | ------ | --------------- | --------- | ------------ | ------ | ---------- | +| new-article | ps5 | switch | ps4 | news | news-game | prtimes | videos | special-article | interview | event-report | review | indie-game | + + + ## マギアレコード(Magia Record, 魔法纪录) ### 游戏公告 diff --git a/lib/v2/famitsu/category.js b/lib/v2/famitsu/category.js new file mode 100644 index 000000000..0878b7a7b --- /dev/null +++ b/lib/v2/famitsu/category.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const baseUrl = 'https://www.famitsu.com'; + +module.exports = async (ctx) => { + const { category = 'new-article' } = ctx.params; + const url = `${baseUrl}/search/?category=${category}`; + const { data } = await got(url); + const $ = cheerio.load(data); + + const list = $('.col-12 .card__body') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('.card__title').text(), + link: new URL(item.find('.card__title a').attr('href'), baseUrl).href, + pubDate: timezone(parseDate(item.find('time').attr('datetime'), 'YYYY.MM.DDTHH:mm'), +9), + }; + }) + .filter((item) => item.link.startsWith('https://www.famitsu.com/news/')); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data } = await got(item.link); + const $ = cheerio.load(data); + + // remove ads + $('.article-body__contents-pr-primary').remove(); + + // fix header image + $('.article-body div.media-image').each((_, e) => { + e.tagName = 'img'; + e.attribs.src = e.attribs.style.match(/url\((.+?)\);/)[1]; + delete e.attribs['data-src']; + delete e.attribs.style; + }); + + // remove white space + $('.article-body__contents-img-block, .article-body__contents-img-common-col').each((_, e) => { + delete e.attribs.style; + }); + + item.description = $('.article-body').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + description: $('head meta[name="description"]').attr('content'), + image: 'https://www.famitsu.com/img/1812/favicons/apple-touch-icon.png', + link: url, + item: items, + language: 'ja', + }; +}; diff --git a/lib/v2/famitsu/maintainer.js b/lib/v2/famitsu/maintainer.js new file mode 100644 index 000000000..670170cd9 --- /dev/null +++ b/lib/v2/famitsu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/category/:category?': ['TonyRL'], +}; diff --git a/lib/v2/famitsu/radar.js b/lib/v2/famitsu/radar.js new file mode 100644 index 000000000..5bcec0714 --- /dev/null +++ b/lib/v2/famitsu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'famitsu.com': { + _name: 'ファミ通', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/game.html#ファミ-tong', + source: ['/search'], + target: (_, url) => `/famitsu/category/${new URL(url).searchParams.get('category')}`, + }, + ], + }, +}; diff --git a/lib/v2/famitsu/router.js b/lib/v2/famitsu/router.js new file mode 100644 index 000000000..4f14521ba --- /dev/null +++ b/lib/v2/famitsu/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/category/:category?', require('./category')); +};