From a9f4ab44d3f23a39a088aae663ad7370ecc31667 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:43:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=BF=AB=E7=A7=91?= =?UTF-8?q?=E6=8A=80=20(#8440)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 48 +++++++++++++- lib/v2/mydrivers/index.js | 110 +++++++++++++++++++++++++++++++++ lib/v2/mydrivers/maintainer.js | 3 + lib/v2/mydrivers/radar.js | 13 ++++ lib/v2/mydrivers/router.js | 3 + 5 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 lib/v2/mydrivers/index.js create mode 100644 lib/v2/mydrivers/maintainer.js create mode 100644 lib/v2/mydrivers/radar.js create mode 100644 lib/v2/mydrivers/router.js diff --git a/docs/new-media.md b/docs/new-media.md index cf8eca17c..f599c6309 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1833,7 +1833,53 @@ column 为 third 时可选的 category: -## 快科技(原驱动之家) +## 快科技 + +### 新闻 + + + +::: tip 提示 + +使用 **类型** 表中的两个参数时,编号应留空,如:**最新** 为 [`/mydrivers/new`](https://rsshub.app/mydrivers/new) + +使用 **编号** 表中的参数不应遗漏对应类型参数,如 **电脑** 为 [`/mydrivers/bcid/801`](https://rsshub.app/mydrivers/bcid/801) + +::: + +类型 + +| 最新 | 热门 | +| ---- | ---- | +| new | hot | + +编号 + +| 最新 | 最热 | 电脑 | 手机 | 汽车 | 业界 | +| ------ | ------ | -------- | -------- | -------- | -------- | +| ac/new | ac/hot | bcid/801 | bcid/802 | bcid/807 | bcid/803 | + +| 科学 | 排行 | 评测 | 安卓 | 苹果 | CPU | +| -------- | -------- | -------- | -------- | ------- | ------ | +| tid/1000 | tid/1001 | tid/1002 | icid/121 | cid/201 | cid/13 | + +| 显卡 | 一图 | 阿里 | 微软 | 百度 | 影视 | +| ------ | -------- | -------- | ------- | ------- | -------- | +| cid/12 | tid/1003 | icid/270 | icid/90 | icid/67 | bcid/809 | + +| 游戏 | 路由器 | PS5 | Xbox | 华为 | OPPO | +| -------- | ------ | --------- | -------- | -------- | -------- | +| bcid/806 | cid/38 | icid/6950 | icid/194 | icid/136 | icid/148 | + +| 小米 | VIVO | 三星 | 魅族 | 一加 | 特斯拉 | +| --------- | -------- | -------- | -------- | -------- | --------- | +| icid/9355 | icid/288 | icid/154 | icid/140 | icid/385 | icid/1193 | + +| 比亚迪 | 小鹏 | 蔚来 | 理想 | 奔驰 | 宝马 | 大众 | +| -------- | --------- | --------- | ---------- | -------- | -------- | -------- | +| icid/770 | icid/7259 | icid/7318 | icid/12947 | icid/429 | icid/461 | icid/481 | + + ### 最新新闻 diff --git a/lib/v2/mydrivers/index.js b/lib/v2/mydrivers/index.js new file mode 100644 index 000000000..b7dca23d8 --- /dev/null +++ b/lib/v2/mydrivers/index.js @@ -0,0 +1,110 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +const titles = { + '': { '': '最新' }, + new: { '': '最新' }, + hot: { '': '最热' }, + ac: { + new: '最新', + hot: '最热', + }, + bcid: { + 801: '电脑', + 802: '手机', + 803: '业界', + 806: '游戏', + 807: '汽车', + 809: '影视', + }, + tid: { + 1000: '科学', + 1001: '排行', + 1002: '评测', + 1003: '一图', + }, + icid: { + 67: '百度', + 90: '微软', + 121: '安卓', + 136: '华为', + 140: '魅族', + 148: 'OPPO', + 154: '三星', + 194: 'Xbox', + 270: '阿里', + 288: 'VIVO', + 385: '一加', + 429: '奔驰', + 461: '宝马', + 481: '大众', + 770: '比亚迪', + 1193: '特斯拉', + 6950: 'PS5', + 7259: '小鹏', + 7318: '蔚来', + 9355: '小米', + 12947: '理想', + }, + cid: { + 12: '显卡', + 13: 'CPU', + 38: '路由器', + 201: '苹果', + }, +}; + +module.exports = async (ctx) => { + const type = ctx.params.type ?? ''; + const id = ctx.params.id ?? ''; + + const rootUrl = 'https://m.mydrivers.com'; + const currentUrl = `${rootUrl}/${type === '' || type === 'ac' ? 'm/newslist.ashx' : 'newsclass.aspx'}${type ? (id ? `?${type}=${id}` : `?ac=${type}`) : ''}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.newst a') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${item.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 content = cheerio.load(detailResponse.data); + + content('.ab, .bb').remove(); + + item.author = content('.writer').text(); + item.description = content('#content').html(); + item.pubDate = timezone(parseDate(content('.news_t1 ul li').eq(1).text().trim(), 'YYYY年MM月DD日 mm:ss'), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${titles[type][id]} - 快科技`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/mydrivers/maintainer.js b/lib/v2/mydrivers/maintainer.js new file mode 100644 index 000000000..5930963c0 --- /dev/null +++ b/lib/v2/mydrivers/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:type?/:id?': ['nczitzk'], +}; diff --git a/lib/v2/mydrivers/radar.js b/lib/v2/mydrivers/radar.js new file mode 100644 index 000000000..01842c71e --- /dev/null +++ b/lib/v2/mydrivers/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'mydrivers.com': { + _name: '快科技', + '.': [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/new-media.html#kuai-ke-ji-xin-wen', + source: ['/'], + target: '/mydrivers/:type?/:id?', + }, + ], + }, +}; diff --git a/lib/v2/mydrivers/router.js b/lib/v2/mydrivers/router.js new file mode 100644 index 000000000..5f136f299 --- /dev/null +++ b/lib/v2/mydrivers/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:type?/:id?', require('./index')); +};