From 0e5b0a6207b8eff384c783f4d2b65ec524022aeb Mon Sep 17 00:00:00 2001 From: Lava-Swimmer <58315416+Lava-Swimmer@users.noreply.github.com> Date: Mon, 2 Dec 2019 15:27:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Add=20Nyaa=E6=90=9C=E7=B4=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=20(#3511)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/multimedia.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/nyaa/search.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 lib/routes/nyaa/search.js diff --git a/docs/multimedia.md b/docs/multimedia.md index e82e0060b..a1eb6881f 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -126,6 +126,12 @@ pageClass: routes +## Nyaa + +### 搜索结果 + + + ## rs05 人生 05 电影 ### rs05 电影列表 diff --git a/lib/router.js b/lib/router.js index 046be0783..5beca527a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2007,6 +2007,9 @@ router.get('/transferwise/pair/:source/:target', require('./routes/transferwise/ // chocolatey router.get('/chocolatey/software/:name?', require('./routes/chocolatey/software')); +// Nyaa +router.get('/nyaa/search/:query?', require('./routes/nyaa/search')); + // 片源网 router.get('/pianyuan/:media?', require('./routes/pianyuan/app')); diff --git a/lib/routes/nyaa/search.js b/lib/routes/nyaa/search.js new file mode 100644 index 000000000..acb199832 --- /dev/null +++ b/lib/routes/nyaa/search.js @@ -0,0 +1,31 @@ +const config = require('@/config').value; +const Parser = require('rss-parser'); + +module.exports = async (ctx) => { + const parser = new Parser({ + customFields: { + item: ['magnet', ['nyaa:infoHash', 'infoHash']], + }, + headers: { + 'User-Agent': config.ua, + }, + }); + + const { query = '' } = ctx.params; + const feed = await parser.parseURL(`https://nyaa.uk/?page=rss&c=0_0&f=0&q=${encodeURI(query)}`); + + feed.items.map((item) => { + item.link = item.guid; + item.description = item.content; + item.enclosure_url = `magnet:?xt=urn:btih:${item.infoHash}`; + item.enclosure_type = 'application/x-bittorrent'; + return item; + }); + + ctx.state.data = { + title: feed.title, + link: `https://nyaa.uk/?f=0&c=0_0&q=${query}`, + description: feed.description, + item: feed.items, + }; +};