Skip to content

Commit

Permalink
fix(route): agefans (#12851)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL committed Jul 21, 2023
1 parent cfd5224 commit 758a791
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 40 deletions.
35 changes: 20 additions & 15 deletions lib/v2/agefans/detail.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { rootUrl } = require('./utils');

module.exports = async (ctx) => {
const response = await got(`https://www.agemys.cc/detail/${ctx.params.id}`);
const response = await got(`${rootUrl}/detail/${ctx.params.id}`);
const $ = cheerio.load(response.data);

const defaultIdx = parseInt($('#DEF_PLAYINDEX').get(0).children[0].data);
const items = $('#main0 div')
.filter((idx) => defaultIdx === idx)
.find('a')
.map((idx, item) => ({
title: $(item).text(),
description: $(item).text(),
link: `https://www.agemys.cc${$(item).attr('href')}`,
}))
.get();
items.reverse();
const ldJson = JSON.parse($('script[type="application/ld+json"]').text());

const items = $('.video_detail_episode')
.first()
.find('li')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: a.attr('href').replace('http://', 'https://'),
};
})
.reverse();

ctx.state.data = {
title: `AGE动漫 - ${$('.detail_imform_name').text()}`,
link: `https://www.agemys.cc/detail/${ctx.params.id}`,
description: $('.detail_imform_desc_pre').text(),
title: `AGE动漫 - ${ldJson.name}`,
link: `${rootUrl}/detail/${ctx.params.id}`,
description: ldJson.description,
item: items,
};
};
37 changes: 20 additions & 17 deletions lib/v2/agefans/radar.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
const ageFans = {
_name: 'AGE动漫',
'.': [
{
title: '最近更新',
docs: 'https://docs.rsshub.app/anime.html#age-dong-man',
source: ['/update', '/'],
target: '/agefans/update',
},
{
title: '番剧详情',
docs: 'https://docs.rsshub.app/anime.html#age-dong-man',
source: ['/detail/:id'],
target: '/agefans/detail/:id',
},
],
};

module.exports = {
'agemys.cc': {
_name: 'AGE动漫',
'.': [
{
title: '最近更新',
docs: 'https://docs.rsshub.app/anime.html#age-dong-man',
source: ['/update', '/'],
target: '/agefans/update',
},
{
title: '番剧详情',
docs: 'https://docs.rsshub.app/anime.html#age-dong-man',
source: ['/detail/:id'],
target: '/agefans/detail/:id',
},
],
},
'agemys.cc': ageFans,
'agemys.org': ageFans,
};
25 changes: 17 additions & 8 deletions lib/v2/agefans/update.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { rootUrl } = require('./utils');

module.exports = async (ctx) => {
const rootUrl = 'https://www.agemys.cc';
const currentUrl = `${rootUrl}/update`;
const response = await got(currentUrl);

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

const list = $('.anime_icon2_name a')
.map((_, item) => {
const list = $('.video_item')
.toArray()
.map((item) => {
item = $(item);
const link = item.find('a').attr('href').replace('http://', 'https://');
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
guid: `${rootUrl}${item.attr('href')}#${item.parent().prev().find('.anime_icon1_name1').text()}`,
link,
guid: `${link}#${item.find('.video_item--info').text()}`,
};
})
.get();
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);

item.description = content('.div_left').html();
content('img').each((_, ele) => {
if (ele.attribs['data-original']) {
ele.attribs.src = ele.attribs['data-original'];
delete ele.attribs['data-original'];
}
});
content('.video_detail_collect').remove();

item.description = content('.video_detail_left').html();

return item;
})
Expand Down
5 changes: 5 additions & 0 deletions lib/v2/agefans/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const rootUrl = 'https://www.agemys.org';

module.exports = {
rootUrl,
};

0 comments on commit 758a791

Please sign in to comment.