diff --git a/lib/router.js b/lib/router.js index 23398f1eb..86b281f7c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3331,9 +3331,9 @@ router.get('/huawei/xinsheng/:caty?/:order?/:keyword?', lazyloadRouteHandler('./ router.get('/ow/patch', lazyloadRouteHandler('./routes/ow/patch')); // MM范 -router.get('/95mm/tab/:tab?', lazyloadRouteHandler('./routes/95mm/tab')); -router.get('/95mm/tag/:tag', lazyloadRouteHandler('./routes/95mm/tag')); -router.get('/95mm/category/:category', lazyloadRouteHandler('./routes/95mm/category')); +// router.get('/95mm/tab/:tab?', lazyloadRouteHandler('./routes/95mm/tab')); +// router.get('/95mm/tag/:tag', lazyloadRouteHandler('./routes/95mm/tag')); +// router.get('/95mm/category/:category', lazyloadRouteHandler('./routes/95mm/category')); // 中国工程科技知识中心 router.get('/cktest/app/:ctgroup?/:domain?', lazyloadRouteHandler('./routes/cktest/app')); diff --git a/lib/routes/95mm/tab.js b/lib/routes/95mm/tab.js deleted file mode 100644 index 619de6dbd..000000000 --- a/lib/routes/95mm/tab.js +++ /dev/null @@ -1,9 +0,0 @@ -const utils = require('./utils'); - -module.exports = async (ctx) => { - ctx.params.tab = ctx.params.tab || '最新'; - - const rootUrl = `https://www.95mm.net/home-ajax/index.html?tabcid=${ctx.params.tab}&page=1`; - - ctx.state.data = await utils(ctx, ctx.params.tab, rootUrl); -}; diff --git a/lib/routes/95mm/tag.js b/lib/routes/95mm/tag.js deleted file mode 100644 index 0176aaac7..000000000 --- a/lib/routes/95mm/tag.js +++ /dev/null @@ -1,7 +0,0 @@ -const utils = require('./utils'); - -module.exports = async (ctx) => { - const rootUrl = `https://www.95mm.net/tag-${ctx.params.tag}/page-1/index.html`; - - ctx.state.data = await utils(ctx, ctx.params.tag, rootUrl); -}; diff --git a/lib/routes/95mm/utils.js b/lib/routes/95mm/utils.js deleted file mode 100644 index 71aa72e4a..000000000 --- a/lib/routes/95mm/utils.js +++ /dev/null @@ -1,51 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx, title, rootUrl) => { - const response = await got({ - method: 'get', - url: rootUrl, - header: { - Referer: 'https://www.95mm.net', - }, - }); - - const $ = cheerio.load(response.data); - - const list = $('div.list-body') - .map((_, item) => { - item = $(item); - const a = item.find('a'); - return { - title: a.text(), - link: a.attr('href'), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const images = detailResponse.data.match(/src": '(.*?)',"width/g); - - item.description = ''; - - for (const i of images) { - item.description += ``; - } - - return item; - }) - ) - ); - - return { - title: `${title} - MM范`, - link: rootUrl, - item: items, - }; -}; diff --git a/lib/routes/95mm/category.js b/lib/v2/95mm/category.js similarity index 52% rename from lib/routes/95mm/category.js rename to lib/v2/95mm/category.js index cf164d180..43baec875 100644 --- a/lib/routes/95mm/category.js +++ b/lib/v2/95mm/category.js @@ -1,4 +1,4 @@ -const utils = require('./utils'); +const { rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { const categories = { @@ -12,7 +12,9 @@ module.exports = async (ctx) => { 11: '美女壁纸', }; - const rootUrl = `https://www.95mm.net/category-${ctx.params.category}/list-1/index.html?page=1`; + const category = ctx.params.category; - ctx.state.data = await utils(ctx, categories[ctx.params.category], rootUrl); + const currentUrl = `${rootUrl}/category-${category}/list-1/index.html?page=1`; + + ctx.state.data = await ProcessItems(ctx, categories[category], currentUrl); }; diff --git a/lib/v2/95mm/maintainer.js b/lib/v2/95mm/maintainer.js new file mode 100644 index 000000000..377d171d0 --- /dev/null +++ b/lib/v2/95mm/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/tab/:tab?': ['nczitzk'], + '/tag/:tag': ['nczitzk'], + '/category/:category': ['nczitzk'], +}; diff --git a/lib/v2/95mm/radar.js b/lib/v2/95mm/radar.js new file mode 100644 index 000000000..67310c355 --- /dev/null +++ b/lib/v2/95mm/radar.js @@ -0,0 +1,25 @@ +module.exports = { + '95mm.org': { + _name: 'MM范', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/picture.html#mm-fan-fen-lei', + source: '/', + target: '/95mm/tab/:tab?', + }, + { + title: '标签', + docs: 'https://docs.rsshub.app/picture.html#mm-fan-biao-qian', + source: '/', + target: '/95mm/tag/:tag', + }, + { + title: '集合', + docs: 'https://docs.rsshub.app/picture.html#mm-fan-ji-he', + source: '/', + target: '/95mm/category/:category', + }, + ], + }, +}; diff --git a/lib/v2/95mm/router.js b/lib/v2/95mm/router.js new file mode 100644 index 000000000..317035534 --- /dev/null +++ b/lib/v2/95mm/router.js @@ -0,0 +1,5 @@ +module.exports = function (router) { + router.get('/tab/:tab?', require('./tab')); + router.get('/tag/:tag', require('./tag')); + router.get('/category/:category', require('./category')); +}; diff --git a/lib/v2/95mm/tab.js b/lib/v2/95mm/tab.js new file mode 100644 index 000000000..1e2dc42c1 --- /dev/null +++ b/lib/v2/95mm/tab.js @@ -0,0 +1,9 @@ +const { rootUrl, ProcessItems } = require('./utils'); + +module.exports = async (ctx) => { + const tab = ctx.params.tab ?? '最新'; + + const currentUrl = `${rootUrl}/home-ajax/index.html?tabcid=${tab}&page=1`; + + ctx.state.data = await ProcessItems(ctx, tab, currentUrl); +}; diff --git a/lib/v2/95mm/tag.js b/lib/v2/95mm/tag.js new file mode 100644 index 000000000..d78463728 --- /dev/null +++ b/lib/v2/95mm/tag.js @@ -0,0 +1,9 @@ +const { rootUrl, ProcessItems } = require('./utils'); + +module.exports = async (ctx) => { + const tag = ctx.params.tag; + + const currentUrl = `${rootUrl}/tag-${tag}/page-1/index.html`; + + ctx.state.data = await ProcessItems(ctx, tag, currentUrl); +}; diff --git a/lib/v2/95mm/templates/description.art b/lib/v2/95mm/templates/description.art new file mode 100644 index 000000000..f60deb835 --- /dev/null +++ b/lib/v2/95mm/templates/description.art @@ -0,0 +1,3 @@ +{{ each images }} + +{{ /each }} diff --git a/lib/v2/95mm/utils.js b/lib/v2/95mm/utils.js new file mode 100644 index 000000000..a908ea529 --- /dev/null +++ b/lib/v2/95mm/utils.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const rootUrl = 'https://www.95mm.org'; + +module.exports = { + rootUrl, + ProcessItems: async (ctx, title, currentUrl) => { + const response = await got({ + method: 'get', + url: currentUrl, + header: { + Referer: rootUrl, + }, + }); + + const $ = cheerio.load(response.data); + + let items = $('div.list-body') + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('a'); + + return { + title: a.text(), + link: a.attr('href'), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const images = detailResponse.data.match(/src": '(.*?)',"width/g); + + item.description = art(path.join(__dirname, 'templates/description.art'), { + images: images.map((i) => i.split("'")[1]), + }); + + return item; + }) + ) + ); + + return { + title: `${title} - MM范`, + link: currentUrl, + item: items, + }; + }, +};