From b39ee6709ee1692a31445aceee45387ea1f0ce20 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Tue, 9 Aug 2022 19:52:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=90=8C=E7=95=AA?= =?UTF-8?q?=E7=BB=84=20(#10427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): bump rand-user-agent from 1.0.74 to 1.0.76 (#254) Bumps [rand-user-agent](https://github.com/WebScrapingAPI/rand-user-agent) from 1.0.74 to 1.0.76. - [Release notes](https://github.com/WebScrapingAPI/rand-user-agent/releases) - [Commits](https://github.com/WebScrapingAPI/rand-user-agent/commits) --- updated-dependencies: - dependency-name: rand-user-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump puppeteer-extra-plugin-stealth from 2.11.0 to 2.11.1 (#256) Bumps [puppeteer-extra-plugin-stealth](https://github.com/berstend/puppeteer-extra) from 2.11.0 to 2.11.1. - [Release notes](https://github.com/berstend/puppeteer-extra/releases) - [Commits](https://github.com/berstend/puppeteer-extra/compare/puppeteer-extra-plugin-stealth@2.11.0...puppeteer-extra-plugin-stealth@2.11.1) --- updated-dependencies: - dependency-name: puppeteer-extra-plugin-stealth dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(route): add 萌番组 * fix: radar Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/anime.md | 14 ++++++ docs/en/anime.md | 14 ++++++ lib/v2/bangumi/index.js | 92 ++++++++++++++++++++++++++++++++++++ lib/v2/bangumi/maintainer.js | 4 ++ lib/v2/bangumi/radar.js | 19 ++++++++ lib/v2/bangumi/router.js | 3 ++ 6 files changed, 146 insertions(+) create mode 100644 lib/v2/bangumi/index.js create mode 100644 lib/v2/bangumi/maintainer.js create mode 100644 lib/v2/bangumi/radar.js create mode 100644 lib/v2/bangumi/router.js diff --git a/docs/anime.md b/docs/anime.md index 8379341b79..18ebf64f29 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -531,6 +531,20 @@ Sources +## 萌番组 + +### 最新 + + + +### 标签 + + + +更多标签请前往 [搜索种子](https://bangumi.moe/search/index) + + + ## 三界异次元 ### 三界异次元 diff --git a/docs/en/anime.md b/docs/en/anime.md index a76408d566..2b50cebb8a 100644 --- a/docs/en/anime.md +++ b/docs/en/anime.md @@ -4,6 +4,20 @@ pageClass: routes # ACG +## Bangumi Moe + +### Latest + + + +### Tags + + + +For more tags, please go to [Search torrent](https://bangumi.moe/search/index) + + + ## Hanime.tv ### Recently updated diff --git a/lib/v2/bangumi/index.js b/lib/v2/bangumi/index.js new file mode 100644 index 0000000000..4e5bb27be9 --- /dev/null +++ b/lib/v2/bangumi/index.js @@ -0,0 +1,92 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const isLatest = ctx.path === '/'; + const rootUrl = 'https://bangumi.moe'; + + let response; + let tag_id = []; + + if (isLatest) { + const apiUrl = `${rootUrl}/api/torrent/latest`; + + response = await got({ + method: 'get', + url: apiUrl, + }); + } else { + const tagUrl = `${rootUrl}/api/tag/search`; + const torrentUrl = `${rootUrl}/api/torrent/search`; + + const params = ctx.path.split('/').slice(1); + + tag_id = await Promise.all( + params.map((param) => + ctx.cache.tryGet(param, async () => { + const paramResponse = await got({ + method: 'post', + url: tagUrl, + json: { + name: decodeURIComponent(param), + keywords: true, + multi: true, + }, + }); + + return paramResponse.data.found ? paramResponse.data.tag.map((tag) => tag._id)[0] : ''; + }) + ) + ); + + response = await got({ + method: 'post', + url: torrentUrl, + json: { + tag_id, + }, + }); + } + + let items = + response.data.torrents?.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 30).map((item) => ({ + title: item.title, + link: `${rootUrl}/torrent/${item._id}`, + description: item.introduction, + pubDate: parseDate(item.publish_time), + enclosure_url: item.magnet, + enclosure_type: 'application/x-bittorrent', + category: item.tag_ids, + })) ?? []; + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'post', + url: `${rootUrl}/api/tag/fetch`, + json: { + _ids: item.category, + }, + }); + + item.category = []; + + for (const tag of detailResponse.data) { + for (const t of tag.synonyms) { + item.category.push(t); + } + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: '萌番组 Bangumi Moe', + link: isLatest || items.length === 0 ? rootUrl : `${rootUrl}/search/${tag_id.join('+')}`, + item: items, + allowEmpty: true, + }; +}; diff --git a/lib/v2/bangumi/maintainer.js b/lib/v2/bangumi/maintainer.js new file mode 100644 index 0000000000..b4a30df315 --- /dev/null +++ b/lib/v2/bangumi/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/': ['nczitzk'], + '/:tags?': ['nczitzk'], +}; diff --git a/lib/v2/bangumi/radar.js b/lib/v2/bangumi/radar.js new file mode 100644 index 0000000000..98c9fbc769 --- /dev/null +++ b/lib/v2/bangumi/radar.js @@ -0,0 +1,19 @@ +module.exports = { + '萌番组 Bangumi Moe': { + _name: 'bangumi.moe', + '.': [ + { + title: '最新', + docs: 'https://docs.rsshub.app/anime.html#meng-fan-zu-zui-xin', + source: ['/'], + target: '/bangumi', + }, + { + title: '标签', + docs: 'https://docs.rsshub.app/anime.html#meng-fan-zu-biao-qian', + source: ['/search/index'], + target: '/bangumi/:tags?', + }, + ], + }, +}; diff --git a/lib/v2/bangumi/router.js b/lib/v2/bangumi/router.js new file mode 100644 index 0000000000..4063156855 --- /dev/null +++ b/lib/v2/bangumi/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get(/([\w-/]+)?/, require('./index')); +};