From 817f683a6a4e9cd631727b4dacab4d94ec8a392a Mon Sep 17 00:00:00 2001 From: Beisi Xu Date: Thu, 16 Nov 2023 08:31:09 -0600 Subject: [PATCH] fix(route): zimuxia portfolio.js compatible for old stype and support ed2k baidu (#13783) * fix(route): zimuxia portfolio.js compatible for old stype and support ed2k page like https://www.zimuxia.cn/portfolio/9%E5%8F%B7%E7%A7%98%E4%BA%8B the a were not wrap in div or p, only seperated by
https://rsshub.app/zimuxia/portfolio/9%E5%8F%B7%E7%A7%98%E4%BA%8B * lint * limited regex to a list to avoid vulnerability * fix doc * fix doc --------- Co-authored-by: Beisi Xu --- lib/v2/zimuxia/portfolio.js | 15 ++++++++------- website/docs/routes/multimedia.mdx | 6 ++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/v2/zimuxia/portfolio.js b/lib/v2/zimuxia/portfolio.js index b4888c27d5..148b2eb0be 100644 --- a/lib/v2/zimuxia/portfolio.js +++ b/lib/v2/zimuxia/portfolio.js @@ -1,8 +1,12 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const allowlinktypes = [ 'all', 'magnet', 'ed2k', 'baidu', 'subhd', 'quark', '115' ]; module.exports = async (ctx) => { const id = ctx.params.id; + let linktype = ctx.query.linktype ?? 'magnet'; + linktype = allowlinktypes.includes(linktype) ? linktype : 'magnet'; + linktype = linktype === "all" ? "." : linktype; const rootUrl = 'https://www.zimuxia.cn'; const currentUrl = `${rootUrl}/portfolio/${id}`; @@ -17,16 +21,13 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); const items = $('a') - .filter((_, el) => $(el).attr('href')?.startsWith('magnet:')) + .filter((_, el) => $(el).attr('href')?.match(RegExp(linktype))) .toArray() .map((item) => { item = $(item); - const title = item - .parent() - .contents() - .filter((_, el) => el.type === 'text') - .text() - .trim(); + const tmpstr2match = $.html(item.parent().children()[item.prevAll("br").first().index() + 1]); + const tmphtml = item.parent().contents().toArray().map((item) => $.html($(item))); + const title = tmphtml[tmphtml.indexOf(tmpstr2match) - 1].trim().replace(/\s.*| .*/, ""); return { link: currentUrl, diff --git a/website/docs/routes/multimedia.mdx b/website/docs/routes/multimedia.mdx index 2685f82389..4b936b5bed 100644 --- a/website/docs/routes/multimedia.mdx +++ b/website/docs/routes/multimedia.mdx @@ -535,6 +535,12 @@ Official RSS: [https://eztv.io/ezrss.xml](https://eztv.io/ezrss.xml) +:::tip + +本路由以 `magnet` 为默认linktype,可以通过在路由后方加上 `?linktype=链接类型` 指定导出的链接类型。比如路由为 [`/zimuxia/portfolio/我们这一天?linktype=baidu`](https://rsshub.app/zimuxia/portfolio/我们这一天?linktype=baidu) 来导出百度盘链接. 目前,你可以选择的 `链接类型` 包括: `magnet`(默认), `all`(所有), `ed2k`(电驴), `baidu`(百度盘), `quark`(夸克盘), `115`(115盘), `subhd`(字幕). + +::: + ### Lookup Torrents by IMDB ID {#fix-zi-mu-xia-lookup-torrents-by-imdb-id}