feat: Add Nyaa搜索结果 (#3511)
This commit is contained in:
parent
32c5513457
commit
0e5b0a6207
|
|
@ -126,6 +126,12 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## Nyaa
|
||||
|
||||
### 搜索结果
|
||||
|
||||
<Route author="Lava-Swimmer" example="/nyaa/search/psycho-pass" path="/nyaa/search/:keyword" :paramsDesc="['搜索关键字']" supportBT="1"/>
|
||||
|
||||
## rs05 人生 05 电影
|
||||
|
||||
### rs05 电影列表
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue