From 99b63f9755a31c636b7439bf5dc2ca2e51162b07 Mon Sep 17 00:00:00 2001
From: noname1897 <108270972+noname1897@users.noreply.github.com>
Date: Wed, 20 Jul 2022 23:45:06 +0800
Subject: [PATCH] feat(route): add nyaa and sukebei.nyaa USER route (#10284)
* feat(route): add nyaa and sukebei.nyaa user route
new route:
- `/nyaa/user/Tsundere-Raws`
- `/nyaa/sukebei/user/Tarakara168`
* fix(nyaa): add nyaa/sukebei.nyaa USER maintainer
add user route infomation in nyaa/maintainer.js
fix typo (change subekei to sukebei)
---
docs/en/multimedia.md | 8 ++++++
docs/multimedia.md | 8 ++++++
lib/v2/nyaa/main.js | 57 +++++++++++++++++++++++++++++++++++++++
lib/v2/nyaa/maintainer.js | 4 ++-
lib/v2/nyaa/radar.js | 17 ++++++++++++
lib/v2/nyaa/router.js | 7 +++--
lib/v2/nyaa/search.js | 33 -----------------------
7 files changed, 98 insertions(+), 36 deletions(-)
create mode 100644 lib/v2/nyaa/main.js
delete mode 100644 lib/v2/nyaa/search.js
diff --git a/docs/en/multimedia.md b/docs/en/multimedia.md
index 6aa901f87b..670d014fb7 100644
--- a/docs/en/multimedia.md
+++ b/docs/en/multimedia.md
@@ -265,10 +265,18 @@ See [Directory](https://www.javlibrary.com/en/star_list.php) to view all stars.
+### User
+
+
+
### Sukebei Search Result
+### Sukebei User
+
+
+
## PornHub
### Category
diff --git a/docs/multimedia.md b/docs/multimedia.md
index d7557a69c6..29595ac553 100644
--- a/docs/multimedia.md
+++ b/docs/multimedia.md
@@ -902,10 +902,18 @@ JavDB 有多个备用域名,本路由默认使用永久域名
+### 用户
+
+
+
### Sukebei 搜索结果
+### Sukebei 用户
+
+
+
## OneJAV
::: tip 提示
diff --git a/lib/v2/nyaa/main.js b/lib/v2/nyaa/main.js
new file mode 100644
index 0000000000..46a2977abb
--- /dev/null
+++ b/lib/v2/nyaa/main.js
@@ -0,0 +1,57 @@
+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,
+ },
+ });
+
+ let currentURL;
+ let currentLink;
+
+ if (ctx.routerPath.split('/')[1] === 'sukebei') {
+ const rootURL = 'https://sukebei.nyaa.si';
+ const { username = 'ohys' } = ctx.params;
+ const { query = '' } = ctx.params;
+ if (ctx.routerPath.split('/')[2] === 'user') {
+ currentURL = `${rootURL}/?page=rss&u=${username}`;
+ currentLink = `${rootURL}/user/${username}`;
+ } else {
+ currentURL = `${rootURL}/?page=rss&c=0_0&f=0&q=${encodeURI(query)}`;
+ currentLink = `${rootURL}/?f=0&c=0_0&q=${query}`;
+ }
+ } else {
+ const rootURL = 'https://nyaa.si';
+ const { username = 'Tarakara168' } = ctx.params;
+ const { query = '' } = ctx.params;
+ if (ctx.routerPath.split('/')[1] === 'user') {
+ currentURL = `${rootURL}/?page=rss&u=${username}`;
+ currentLink = `${rootURL}/user/${username}`;
+ } else {
+ currentURL = `${rootURL}/?page=rss&c=0_0&f=0&q=${encodeURI(query)}`;
+ currentLink = `${rootURL}/?f=0&c=0_0&q=${query}`;
+ }
+ }
+
+ const feed = await parser.parseURL(currentURL);
+
+ 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: currentLink,
+ description: feed.description,
+ item: feed.items,
+ };
+};
diff --git a/lib/v2/nyaa/maintainer.js b/lib/v2/nyaa/maintainer.js
index 31f6194cde..218b51bfaf 100644
--- a/lib/v2/nyaa/maintainer.js
+++ b/lib/v2/nyaa/maintainer.js
@@ -1,4 +1,6 @@
module.exports = {
'/search/:query?': ['Lava-Swimmer', 'noname1897'],
- '/subekei/search/:query?': ['Lava-Swimmer', 'noname1897'],
+ '/sukebei/search/:query?': ['Lava-Swimmer', 'noname1897'],
+ '/user/:username?': ['Lava-Swimmer', 'noname1897'],
+ '/sukebei/user/:username?': ['Lava-Swimmer', 'noname1897'],
};
diff --git a/lib/v2/nyaa/radar.js b/lib/v2/nyaa/radar.js
index 0eedcbff83..2c61e85532 100644
--- a/lib/v2/nyaa/radar.js
+++ b/lib/v2/nyaa/radar.js
@@ -15,6 +15,17 @@ module.exports = {
}
},
},
+ {
+ title: '用户',
+ docs: 'https://docs.rsshub.app/multimedia.html#nyaa-yong-hu',
+ source: '/user/:username',
+ target: (params, url) => {
+ url = new URL(url);
+ if (url.hostname.split('.')[0] === 'nyaa') {
+ return `/nyaa/user/${params.username}`;
+ }
+ },
+ },
],
sukebei: [
{
@@ -27,6 +38,12 @@ module.exports = {
return `/nyaa/sukebei/search/${query}`;
},
},
+ {
+ title: 'sukebei 用户',
+ docs: 'https://docs.rsshub.app/multimedia.html#nyaa-sukebei-yong-hu',
+ source: '/user/:username',
+ target: (params) => `/nyaa/sukebei/user/${params.username}`,
+ },
],
},
};
diff --git a/lib/v2/nyaa/router.js b/lib/v2/nyaa/router.js
index 7193e2c9de..6c4f092c2c 100644
--- a/lib/v2/nyaa/router.js
+++ b/lib/v2/nyaa/router.js
@@ -1,4 +1,7 @@
module.exports = (router) => {
- router.get('/search/:query?', require('./search'));
- router.get('/sukebei/search/:query?', require('./search'));
+ router.get('/search/:query?', require('./main'));
+ router.get('/sukebei/search/:query?', require('./main'));
+
+ router.get('/user/:username?', require('./main'));
+ router.get('/sukebei/user/:username?', require('./main'));
};
diff --git a/lib/v2/nyaa/search.js b/lib/v2/nyaa/search.js
deleted file mode 100644
index 80151f3cd4..0000000000
--- a/lib/v2/nyaa/search.js
+++ /dev/null
@@ -1,33 +0,0 @@
-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 rootURL = ctx.routerPath.split('/')[1] === 'sukebei' ? 'https://sukebei.nyaa.si' : 'https://nyaa.si';
- const { query = '' } = ctx.params;
-
- const feed = await parser.parseURL(`${rootURL}/?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: `${rootURL}/?f=0&c=0_0&q=${query}`,
- description: feed.description,
- item: feed.items,
- };
-};