const axios = require('../../utils/axios');
const { load } = require('cheerio');
exports.getPage = async (url, ctx) => {
const { data } = await axios(url);
const $ = load(data);
const pageTitle = `JavBus - ${$('head > title')
.text()
.replace(' - JavBus', '')}`;
return {
title: pageTitle,
link: url,
description: pageTitle,
item: await Promise.all(parseItems($, ctx)),
};
};
exports.createHandler = (url) => async (ctx) => {
ctx.state.data = await exports.getPage(url, ctx);
};
const parseItems = ($, ctx) =>
$('.movie-box')
.map((_, ele) => ({
title: $(ele)
.find('img')
.attr('title'),
thumb: $(ele)
.find('img')
.attr('src'),
link: $(ele).attr('href'),
pubDate: new Date(
$(ele)
.find('date:nth-child(4)')
.text()
).toUTCString(),
aid: $(ele)
.find('date:nth-child(3)')
.text(),
}))
.toArray()
.map(async ({ title, thumb, link, pubDate, aid }) => {
const detail = await getDetail(link, ctx);
title = `${aid} ${title}${detail.filmTime}`;
if (detail.screenData) {
detail.imgHTML = detail.screenData.map((url) => `
`);
}
return {
title,
link,
pubDate,
description: `