From 1a9fc89ff7808870276e0e31672b4aab059c538e Mon Sep 17 00:00:00 2001 From: FeCCC <72006654+FeCCC@users.noreply.github.com> Date: Thu, 18 Aug 2022 08:43:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20iwara=E7=94=A8=E6=88=B7=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E5=88=97=E8=A1=A8=20(#10517)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): iwara用户订阅列表 * Update Error message in iwara subscription Co-authored-by: FeCCC <964575805@qq.com> --- docs/anime.md | 12 ++++++ docs/en/anime.md | 12 ++++++ docs/en/install/README.md | 4 ++ docs/install/README.md | 4 ++ lib/config.js | 3 ++ lib/v2/iwara/maintainer.js | 1 + lib/v2/iwara/radar.js | 6 +++ lib/v2/iwara/router.js | 1 + lib/v2/iwara/subscriptions.js | 48 ++++++++++++++++++++++++ lib/v2/iwara/templates/subscriptions.art | 1 + 10 files changed, 92 insertions(+) create mode 100644 lib/v2/iwara/subscriptions.js create mode 100644 lib/v2/iwara/templates/subscriptions.art diff --git a/docs/anime.md b/docs/anime.md index 20c115eefe..1f52d8e59b 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -327,6 +327,18 @@ pageClass: routes +### 用户订阅列表 + + + +::: warning 注意 + +用户动态需要 iwara 登录后的 Cookie 值,所以只能自建,详情见[部署页面](/install/#route-specific-configurations)的配置模块。 + +::: + + + ## Kemono ### Posts diff --git a/docs/en/anime.md b/docs/en/anime.md index a43c09e627..c059f8eaa8 100644 --- a/docs/en/anime.md +++ b/docs/en/anime.md @@ -36,6 +36,18 @@ For more tags, please go to [Search torrent](https://bangumi.moe/search/index) +### User Subscriptions + + + +::: warning + +This route requires Cookie, therefore it's only available when self-hosting, refer to the [Deploy Guide](/en/install/#route-specific-configurations) for route-specific configurations. + +::: + + + ## Kemono ### Posts diff --git a/docs/en/install/README.md b/docs/en/install/README.md index 3cfa1253ef..5caa219c0d 100644 --- a/docs/en/install/README.md +++ b/docs/en/install/README.md @@ -626,6 +626,10 @@ See docs of the specified route and `lib/config.js` for detailed information. Warning: Two Factor Authentication is **not** supported. +- Iwara: + + - `IWARA_COOKIE`: Cookie of Iwara User + - Last.fm - `LASTFM_API_KEY`: Last.fm API Key diff --git a/docs/install/README.md b/docs/install/README.md index ca62195338..c23305b831 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -663,6 +663,10 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行 注意,暂**不支持**两步验证。 +- Iwara: + + - `IWARA_COOKIE`: Iwara 登录后的 Cookie 值 + - Last.fm 全部路由:[申请地址](https://www.last.fm/api/) - `LASTFM_API_KEY`: Last.fm API Key diff --git a/lib/config.js b/lib/config.js index a567b2c16a..6022cf3ca0 100644 --- a/lib/config.js +++ b/lib/config.js @@ -178,6 +178,9 @@ const calculateValue = () => { password: envs.IG_PASSWORD, proxy: envs.IG_PROXY, }, + iwara: { + cookie: envs.IWARA_COOKIE, + }, lastfm: { api_key: envs.LASTFM_API_KEY, }, diff --git a/lib/v2/iwara/maintainer.js b/lib/v2/iwara/maintainer.js index 420abffa78..77b8aafc88 100644 --- a/lib/v2/iwara/maintainer.js +++ b/lib/v2/iwara/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/users/:username?/:type?': ['Fatpandac'], + '/subscriptions': ['FeCCC'], }; diff --git a/lib/v2/iwara/radar.js b/lib/v2/iwara/radar.js index c34fdc7441..e017ced2eb 100644 --- a/lib/v2/iwara/radar.js +++ b/lib/v2/iwara/radar.js @@ -14,6 +14,12 @@ module.exports = { source: '/users/:username', target: '/iwara/users/:username?/image', }, + { + title: '用户订阅列表', + docs: 'https://docs.rsshub.app/anime.html#iwara', + source: '', + target: '/iwara/subscriptions', + }, ], }, }; diff --git a/lib/v2/iwara/router.js b/lib/v2/iwara/router.js index 526b36c30b..e32a8849fd 100644 --- a/lib/v2/iwara/router.js +++ b/lib/v2/iwara/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { router.get('/users/:username?/:type?', require('./index')); + router.get('/subscriptions', require('./subscriptions')); }; diff --git a/lib/v2/iwara/subscriptions.js b/lib/v2/iwara/subscriptions.js new file mode 100644 index 0000000000..c4a9f843a4 --- /dev/null +++ b/lib/v2/iwara/subscriptions.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); +const config = require('@/config').value; +const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const rootUrl = `https://ecchi.iwara.tv/subscriptions`; + const cookie = config.iwara.cookie; + + if (cookie === undefined) { + throw Error('Iwara subscription RSS is disabled due to the lack of relevant config'); + } + + const response = await got({ + method: 'get', + url: rootUrl, + headers: { + Cookie: cookie, + }, + }); + const $ = cheerio.load(response.data); + const username = $('a.btn.btn-info.btn-sm.user').text().trim(); + const list = $('div.views-column'); + + const items = list + .map((_, item) => { + const imageUrl = 'https:' + $(item).find('img').attr('src'); + const type = $(item).find('div.field').hasClass('field-type-video') ? 'Video' : 'Image'; + return { + title: $(item).find('h3.title').text(), + author: username, + link: rootUrl + $(item).find('h3.title > a').attr('href'), + category: type, + description: art(path.join(__dirname, 'templates/subscriptions.art'), { + type, + imageUrl, + }), + }; + }) + .get(); + + ctx.state.data = { + title: `${username}'s iwara Subscription`, + link: rootUrl, + item: items, + }; +}; diff --git a/lib/v2/iwara/templates/subscriptions.art b/lib/v2/iwara/templates/subscriptions.art new file mode 100644 index 0000000000..61eef898ac --- /dev/null +++ b/lib/v2/iwara/templates/subscriptions.art @@ -0,0 +1 @@ +

{{ type }}


\ No newline at end of file