From 3478eebd0190a1fcf1a348a9a08820620445a06a Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Sun, 23 Jan 2022 03:20:07 +0800 Subject: [PATCH] add iwara (#8735) Co-authored-by: Tony Co-authored-by: DIYgod --- docs/anime.md | 12 +++++++++++ docs/en/anime.md | 12 +++++++++++ lib/v2/iwara/index.js | 42 ++++++++++++++++++++++++++++++++++++++ lib/v2/iwara/maintainer.js | 3 +++ lib/v2/iwara/radar.js | 19 +++++++++++++++++ lib/v2/iwara/router.js | 3 +++ 6 files changed, 91 insertions(+) create mode 100644 lib/v2/iwara/index.js create mode 100644 lib/v2/iwara/maintainer.js create mode 100644 lib/v2/iwara/radar.js create mode 100644 lib/v2/iwara/router.js diff --git a/docs/anime.md b/docs/anime.md index 633f64fbd4..77d4ee967f 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -253,6 +253,18 @@ pageClass: routes +## iwara + +### 用户 + + + +| type | 视频 | 图片 | +| :--: | :---: | :---: | +| 参数 | video | image | + + + ## Kemono ### Posts diff --git a/docs/en/anime.md b/docs/en/anime.md index 18ae2c4198..be163d94f3 100644 --- a/docs/en/anime.md +++ b/docs/en/anime.md @@ -79,3 +79,15 @@ For example: https://www.webtoons.com/zh-hant/drama/gongzhuweimian/list?title_no ### [Naver](https://comic.naver.com) + +## iwara + +### User + + + +| type | video | image | +| :--: | :---: | :---: | +| | video | image | + + diff --git a/lib/v2/iwara/index.js b/lib/v2/iwara/index.js new file mode 100644 index 0000000000..2fcc50c85d --- /dev/null +++ b/lib/v2/iwara/index.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const rootUrl = 'https://ecchi.iwara.tv'; + +const typeMap = { + video: 'Videos', + image: 'Images', +}; + +const selectorMap = { + video: 'div.node.node-video.node-teaser.node-teaser.clearfix', + image: 'div.node.node-image.node-teaser.node-teaser.clearfix', +}; + +module.exports = async (ctx) => { + const username = ctx.params.username; + const type = ctx.params.type ?? 'video'; + const userUrl = `${rootUrl}/users/${username}`; + + const response = await got.get(userUrl); + const $ = cheerio.load(response.data); + const list = $(selectorMap[type]); + + const items = list + .map((_, item) => { + const imageUrl = 'https:' + $(item).find('img').attr('src'); + return { + title: $(item).find('h3.title').text(), + author: username, + link: rootUrl + $(item).find('h3.title > a').attr('href'), + description: ``, + }; + }) + .get(); + + ctx.state.data = { + title: `${username}'s iwara - ${typeMap[type]}`, + link: userUrl, + item: items, + }; +}; diff --git a/lib/v2/iwara/maintainer.js b/lib/v2/iwara/maintainer.js new file mode 100644 index 0000000000..420abffa78 --- /dev/null +++ b/lib/v2/iwara/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/users/:username?/:type?': ['Fatpandac'], +}; diff --git a/lib/v2/iwara/radar.js b/lib/v2/iwara/radar.js new file mode 100644 index 0000000000..c34fdc7441 --- /dev/null +++ b/lib/v2/iwara/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'iwara.tv': { + _name: 'iwara', + ecchi: [ + { + title: '用户视频', + docs: '', + source: '/users/:username', + target: '/iwara/users/:username?/video', + }, + { + title: '用户图片', + docs: '', + source: '/users/:username', + target: '/iwara/users/:username?/image', + }, + ], + }, +}; diff --git a/lib/v2/iwara/router.js b/lib/v2/iwara/router.js new file mode 100644 index 0000000000..526b36c30b --- /dev/null +++ b/lib/v2/iwara/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/users/:username?/:type?', require('./index')); +};