Skip to content

Commit

Permalink
fix(route): zimuxia portfolio.js (DIYgod#13750)
Browse files Browse the repository at this point in the history
* Update zimuxia portfolio.js

emtpy hrefs such as https://www.zimuxia.cn/portfolio/%e8%a5%bf%e6%b8%b8abc could bug at https://rsshub.app/zimuxia/portfolio/%E8%A5%BF%E6%B8%B8abc

* refactor: migrate to v2

* fix: use optional chaining startswith instead of deprecated substr

---------
  • Loading branch information
xubeisi authored Nov 11, 2023
1 parent 32fd8f6 commit 1c85030
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2545,8 +2545,8 @@ router.get('/wanwansub/info/:id', lazyloadRouteHandler('./routes/wanwansub/info'
router.get('/wanwansub/:id?', lazyloadRouteHandler('./routes/wanwansub/index'));

// FIX 字幕侠
router.get('/zimuxia/portfolio/:id', lazyloadRouteHandler('./routes/zimuxia/portfolio'));
router.get('/zimuxia/:category?', lazyloadRouteHandler('./routes/zimuxia/index'));
// router.get('/zimuxia/portfolio/:id', lazyloadRouteHandler('./routes/zimuxia/portfolio'));
// router.get('/zimuxia/:category?', lazyloadRouteHandler('./routes/zimuxia/index'));

// Hugo 更新日志
router.get('/hugo/releases', lazyloadRouteHandler('./routes/hugo/releases'));
Expand Down
24 changes: 16 additions & 8 deletions lib/routes/zimuxia/index.js → lib/v2/zimuxia/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,51 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const category = ctx.params.category || '';
const { category } = ctx.params;

const rootUrl = 'https://www.zimuxia.cn';
const currentUrl = `${rootUrl}/我们的作品?cat=${category}`;
const currentUrl = `${rootUrl}/我们的作品`;
const response = await got({
method: 'get',
url: currentUrl,
searchParams: {
cat: category ? category : undefined,
},
https: {
rejectUnauthorized: false,
},
});

const $ = cheerio.load(response.data);

const list = $('.pg-item a')
.slice(0, 10)
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);

return {
title: item.find('h2').text(),
link: 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,
https: {
rejectUnauthorized: false,
},
});
const content = cheerio.load(detailResponse.data);

const links = detailResponse.data.match(/<a href="magnet:(.*?)" target="_blank">磁力下载<\/a>/g);

if (links) {
item.enclosure_type = 'application/x-bittorrent';
item.enclosure_url = links.pop().match(/<a href="(.*)" target="_blank">磁力下载<\/a>/)[1];
item.enclosure_url = decodeURIComponent(links.pop().match(/<a href="(.*)" target="_blank">磁力下载<\/a>/)[1]);
}

item.description = content('.content-box').html();
Expand All @@ -50,7 +58,7 @@ module.exports = async (ctx) => {

ctx.state.data = {
title: `${category || 'ALL'} - FIX字幕侠`,
link: currentUrl,
link: response.url,
item: items,
};
};
4 changes: 4 additions & 0 deletions lib/v2/zimuxia/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/portfolio/:id': ['nczitzk'],
'/:category?': ['nczitzk'],
};
22 changes: 15 additions & 7 deletions lib/routes/zimuxia/portfolio.js → lib/v2/zimuxia/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,40 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;

const rootUrl = 'http://zimuxia.cn';
const rootUrl = 'https://www.zimuxia.cn';
const currentUrl = `${rootUrl}/portfolio/${id}`;
const response = await got({
method: 'get',
url: currentUrl,
https: {
rejectUnauthorized: false,
},
});

const $ = cheerio.load(response.data);

const items = $('a')
.filter(function () {
return $(this).attr('href').substr(0, 7) === 'magnet:';
})
.filter((_, el) => $(el).attr('href')?.startsWith('magnet:'))
.toArray()
.reverse()
.map((item) => {
item = $(item);
const title = item
.parent()
.contents()
.filter((_, el) => el.type === 'text')
.text()
.trim();

return {
link: currentUrl,
title: item.parent().text().split(' ')[0],
title,
description: `<p>${item.parent().html()}</p>`,
enclosure_url: item.attr('href'),
enclosure_type: 'application/x-bittorrent',
guid: `${currentUrl}#${title}`,
};
});
})
.reverse();

ctx.state.data = {
title: `${$('.content-page-title').text()} - FIX字幕侠`,
Expand Down
19 changes: 19 additions & 0 deletions lib/v2/zimuxia/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'zimuxia.cn': {
_name: 'FIX 字幕侠',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/routes/multimedia#fix-zi-mu-xia',
source: ['/我们的作品'],
target: (params, url) => `/zimuxia/${new URL(url).searchParams.get('cat')}`,
},
{
title: '剧集',
docs: 'https://docs.rsshub.app/routes/multimedia#fix-zi-mu-xia',
source: ['/portfolio/:id'],
target: '/zimuxia/portfolio/:id',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/zimuxia/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/portfolio/:id', require('./portfolio'));
router.get('/:category?', require('./index'));
};

0 comments on commit 1c85030

Please sign in to comment.