From fb2a407b0257fd64571b479681228ef5ad9166f1 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 11 Apr 2022 11:17:09 -1100 Subject: [PATCH] feat(route): qbittorrent news (#9524) --- docs/en/program-update.md | 6 ++++ docs/program-update.md | 6 ++++ lib/v2/qbittorrent/maintainer.js | 3 ++ lib/v2/qbittorrent/news.js | 53 ++++++++++++++++++++++++++++++++ lib/v2/qbittorrent/radar.js | 13 ++++++++ lib/v2/qbittorrent/router.js | 3 ++ 6 files changed, 84 insertions(+) create mode 100644 lib/v2/qbittorrent/maintainer.js create mode 100644 lib/v2/qbittorrent/news.js create mode 100644 lib/v2/qbittorrent/radar.js create mode 100644 lib/v2/qbittorrent/router.js diff --git a/docs/en/program-update.md b/docs/en/program-update.md index feb4b429d..341d53cc1 100644 --- a/docs/en/program-update.md +++ b/docs/en/program-update.md @@ -305,6 +305,12 @@ Refer to [#minecraft](/en/game.html#minecraft) +## qBittorrent + +### News + + + ## QNAP ### Release Notes diff --git a/docs/program-update.md b/docs/program-update.md index 5e796f71f..778c67c3f 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -360,6 +360,12 @@ pageClass: routes +## qBittorrent + +### 消息 + + + ## QNAP ### Release Notes diff --git a/lib/v2/qbittorrent/maintainer.js b/lib/v2/qbittorrent/maintainer.js new file mode 100644 index 000000000..f825877e0 --- /dev/null +++ b/lib/v2/qbittorrent/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['TonyRL'], +}; diff --git a/lib/v2/qbittorrent/news.js b/lib/v2/qbittorrent/news.js new file mode 100644 index 000000000..6fd530af8 --- /dev/null +++ b/lib/v2/qbittorrent/news.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const config = require('@/config').value; + +module.exports = async (ctx) => { + const baseUrl = 'https://www.qbittorrent.org'; + + const response = await ctx.cache.tryGet( + `${baseUrl}/news.php`, + async () => + ( + await got(`${baseUrl}/news.php`, { + headers: { + Referer: baseUrl, + }, + }) + ).data, + config.cache.routeExpire, + false + ); + + const $ = cheerio.load(response); + + const item = $('.stretcher') + .find('h3') + .toArray() + .map((item) => { + item = $(item); + const pubDate = item + .text() + .split(' - ')[0] + .replace(/\w{3,6}day/, ''); + const title = item.text().split(' - ')[1]; + let description = ''; + // nextUntil() does not work here + while (item.next().length && item.next().get(0).tagName !== 'h3') { + item = item.next(); + description += item.html(); + } + return { + title, + description, + pubDate: parseDate(pubDate, 'MMMM D YYYY'), + }; + }); + + ctx.state.data = { + title: 'qBittorrent News', + link: `${baseUrl}/news.php`, + item, + }; +}; diff --git a/lib/v2/qbittorrent/radar.js b/lib/v2/qbittorrent/radar.js new file mode 100644 index 000000000..e719fed44 --- /dev/null +++ b/lib/v2/qbittorrent/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'qbittorrent.org': { + _name: 'qBittorrent', + '.': [ + { + title: 'News', + docs: 'https://docs.rsshub.app/program-update.html#qbittorrent', + source: ['/news.php', '/'], + target: '/qbittorrent/news', + }, + ], + }, +}; diff --git a/lib/v2/qbittorrent/router.js b/lib/v2/qbittorrent/router.js new file mode 100644 index 000000000..630036b8e --- /dev/null +++ b/lib/v2/qbittorrent/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news', require('./news')); +};