fix(route): 追新番最近更新 (#14751)

* fix(route): 追新番最近更新

* update lib/routes/fanxinzhui/index.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* update lib/routes/fanxinzhui/index.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

---------
This commit is contained in:
Ethan Shen 2024-03-18 02:29:30 +08:00 committed by GitHub
parent 4314e90dc6
commit 7d6bde4e2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 146 additions and 54 deletions

View File

@ -1121,8 +1121,8 @@ router.get('/etoland/:bo_table', lazyloadRouteHandler('./routes/etoland/board'))
router.get('/lntu/jwnews', lazyloadRouteHandler('./routes/universities/lntu/jwnews'));
// 追新番
router.get('/fanxinzhui', lazyloadRouteHandler('./routes/fanxinzhui/latest'));
router.get('/zhuixinfan/list', lazyloadRouteHandler('./routes/fanxinzhui/latest'));
// router.get('/fanxinzhui', lazyloadRouteHandler('./routes/fanxinzhui/latest'));
// router.get('/zhuixinfan/list', lazyloadRouteHandler('./routes/fanxinzhui/latest'));
// blur-studio
router.get('/blur-studio', lazyloadRouteHandler('./routes/blur-studio/index'));

View File

@ -1,52 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseRelativeDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'http://www.fanxinzhui.com';
const currentUrl = `${rootUrl}/lastest`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.la')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const pubDate = item.find('.time');
pubDate.remove();
return {
title: item.text(),
pubDate: parseRelativeDate(pubDate.text()),
link: `${rootUrl}${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,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.middle_box').html();
return item;
})
)
);
ctx.state.data = {
title: '最近更新 - 追新番',
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,125 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import * as path from 'node:path';
export const route: Route = {
path: '/',
name: '最近更新',
url: 'fanxinzhui.com/lastest',
maintainers: ['nczitzk'],
handler,
example: '/fanxinzhui',
categories: ['multimedia'],
radar: [{
source: ['fanxinzhui.com/lastest'],
target: '/',
}],
};
async function handler(ctx) {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30;
const rootUrl = 'https://www.fanxinzhui.com';
const currentUrl = new URL('lastest', rootUrl).href;
const { data: response } = await got(currentUrl);
const $ = load(response);
let items = $('a.la')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);
const season = item.find('span.season').text();
const name = item.find('span.name').text();
const link = new URL(item.prop('href'), rootUrl).href;
return {
title: `${season} ${name}`,
link,
guid: `${link}#${season}`,
pubDate: timezone(parseDate(item.find('span.time').text()), +8),
};
});
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);
const content = load(detailResponse);
item.author = undefined;
item.category = [];
content('div.info ul li').each((_, el) => {
el = content(el);
const key = el.find('span').text().split(/:/)[0];
const value = el.contents().last().text().trim();
if (key === '类型') {
item.category = [...item.category, ...value.split(/\//)];
} else if (key === '首播日期') {
return;
} else {
item.author = `${item.author ? `${item.author}/` : ''}${value}`;
item.category = [...item.category, ...value.split(/\//)].filter((c) => c !== '等');
}
});
content('div.image').each((_, el) => {
el = content(el);
const image = el.find('img').prop('src');
el.replaceWith(
art(path.join(__dirname, 'templates/description.art'), {
images: image
? [
{
src: image.replace(/@\d+,\d+\.\w+$/, ''),
alt: content('div.resource_title h2').text(),
},
]
: undefined,
})
);
});
content('a.password').each((_, el) => {
el = content(el);
el.replaceWith(el.text());
});
item.description = content('div.middle_box').html();
item.enclosure_url = content('p.way span a').prop('href');
return item;
})
)
);
const title = $('title').text();
const image = new URL($('img.logo').prop('src'), rootUrl).href;
return {
item: items,
title,
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: 'zh',
image,
author: title.split(/_/).pop(),
allowEmpty: true,
};
}

View File

@ -0,0 +1,6 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '追新番',
url: 'fanxinzhui.com',
};

View File

@ -0,0 +1,13 @@
{{ if images }}
{{ each images image }}
{{ if image?.src }}
<figure>
<img
{{ if image.alt }}
alt="{{ image.alt }}"
{{ /if }}
src="{{ image.src }}">
</figure>
{{ /if }}
{{ /each }}
{{ /if }}