diff --git a/docs/anime.md b/docs/anime.md index 8379341b7..18ebf64f2 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 a76408d56..2b50cebb8 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 000000000..4e5bb27be --- /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 000000000..b4a30df31 --- /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 000000000..98c9fbc76 --- /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 000000000..406315685 --- /dev/null +++ b/lib/v2/bangumi/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get(/([\w-/]+)?/, require('./index')); +};