Skip to content

Commit

Permalink
Merge pull request #1323 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Mar 20, 2024
2 parents 0b4207b + c8e4273 commit e3e8ce1
Show file tree
Hide file tree
Showing 42 changed files with 1,445 additions and 882 deletions.
3 changes: 2 additions & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export type Config = {
oauthTokenSecrets?: string[];
username?: string;
password?: string;
cookie?: string;
};
weibo: {
app_key?: string;
Expand Down Expand Up @@ -591,7 +592,7 @@ const calculateValue = () => {
oauthTokenSecrets: envs.TWITTER_OAUTH_TOKEN_SECRET?.split(','),
username: envs.TWITTER_USERNAME,
password: envs.TWITTER_PASSWORD,
authenticationSecret: envs.TWITTER_AUTHENTICATION_SECRET,
cookie: envs.TWITTER_COOKIE,
},
weibo: {
app_key: envs.WEIBO_APP_KEY,
Expand Down
3 changes: 0 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,6 @@ router.get('/missevan/drama/:id', lazyloadRouteHandler('./routes/missevan/drama'
// AMD
router.get('/amd/graphicsdrivers/:id/:rid?', lazyloadRouteHandler('./routes/amd/graphicsdrivers'));

// 靠谱新闻
router.get('/kaopunews/:language?', lazyloadRouteHandler('./routes/kaopunews'));

// 光谷社区
router.get('/guanggoo/:category?', lazyloadRouteHandler('./routes/guanggoo/index'));

Expand Down
28 changes: 0 additions & 28 deletions lib/routes-deprecated/kaopunews/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions lib/routes/18comic/templates/description.art
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{ if cover }}
<img src="{{ cover }}">
{{ /if }}
<p>{{ introduction }}</p>
{{ each images image }}
<img src="{{ image }}">
Expand Down
2 changes: 2 additions & 0 deletions lib/routes/18comic/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const ProcessItems = async (ctx, currentUrl, rootUrl) => {
const content = load(detailResponse.data);

item.pubDate = parseDate(content('div[itemprop="datePublished"]').first().attr('content'));
item.updated = parseDate(content('div[itemprop="datePublished"]').last().attr('content'));
item.category = content('span[data-type="tags"]')
.first()
.find('a')
Expand All @@ -65,6 +66,7 @@ const ProcessItems = async (ctx, currentUrl, rootUrl) => {
images: content('.img_zoom_img img')
.toArray()
.map((image) => content(image).attr('data-original')),
cover: content('.thumb-overlay img').first().attr('src'),
});

return item;
Expand Down
205 changes: 129 additions & 76 deletions lib/routes/4ksj/forum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,36 @@ import * as path from 'node:path';
import iconv from 'iconv-lite';

export const route: Route = {
path: '/forum/:id?',
categories: ['multimedia'],
example: '/4ksj/forum',
parameters: { id: '分类 id,默认为最新4K电影' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
path: '/:id?',
name: '分类',
url: '4ksj.com',
maintainers: ['nczitzk'],
handler,
example: '/4ksj/4k-uhd-1',
parameters: { id: '分类 id,默认为最新4K电影' },
description: `:::tip
若订阅 [最新 4K 电影](https://www.4ksj.com/forum-2-1.html),网址为 \`https://www.4ksj.com/forum-2-1.html\`。截取 \`https://www.4ksj.com/forum-\` 到末尾 \`.html\` 的部分 \`2-1\` 作为参数,此时路由为 [\`/4ksj/forum/2-1\`](https://rsshub.app/4ksj/forum/2-1)。
若订阅 [最新 4K 电影](https://www.4ksj.com/4k-uhd-1.html),网址为 \`https://www.4ksj.com/4k-uhd-1.html\`。截取 \`https://www.4ksj.com/\` 到末尾 \`.html\` 的部分 \`4k-uhd-1\` 作为参数,此时路由为 [\`/4ksj/4k-uhd-1\`](https://rsshub.app/4ksj/4k-uhd-1)。
若订阅子分类 [Dolby Vision 纪录片 4K 电影](https://www.4ksj.com/forum-4kdianying-s7-dianyingbiaozhun-3-dytypes-9-1.html),网址为 \`https://www.4ksj.com/forum-4kdianying-s7-dianyingbiaozhun-3-dytypes-9-1.html\`。截取 \`https://www.4ksj.com/forum-\` 到末尾 \`.html\` 的部分 \`4kdianying-s7-dianyingbiaozhun-3-dytypes-9-1\` 作为参数,此时路由为 [\`/4ksj/forum/4kdianying-s7-dianyingbiaozhun-3-dytypes-9-1\`](https://rsshub.app/4ksj/forum/4kdianying-s7-dianyingbiaozhun-3-dytypes-9-1)。
若订阅子分类 [Dolby Vision 动作 4K 电影](https://www.4ksj.com/4k-uhd-s7-display-3-dytypes-1-1.html),网址为 \`https://www.4ksj.com/4k-uhd-s7-display-3-dytypes-1-1.html\`。截取 \`https://www.4ksj.com/forum-\` 到末尾 \`.html\` 的部分 \`4kdianying-s7-dianyingbiaozhun-3-dytypes-9-1\` 作为参数,此时路由为 [\`/4ksj/4k-uhd-s7-display-3-dytypes-1-1\`](https://rsshub.app/4ksj/4k-uhd-s7-display-3-dytypes-1-1)。
:::`,
categories: ['multimedia'],
};

async function handler(ctx) {
const id = ctx.req.param('id') ?? '2-1';
const { id = '4k-uhd-1' } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25;

const rootUrl = 'https://www.4ksj.com';
const currentUrl = `${rootUrl}/forum-${id}.html`;
const currentUrl = new URL(`${id}.html`, rootUrl).href;

const response = await got({
method: 'get',
url: currentUrl,
const { data: response } = await got(currentUrl, {
responseType: 'buffer',
});

const $ = load(iconv.decode(response.data, 'gbk'));
const $ = load(iconv.decode(response, 'gbk'));

const language = 'zh';
const image = $('div.nexlogo img').prop('src');

let items = $('div.nex_cmo_piv a')
.slice(0, limit)
Expand All @@ -56,88 +50,147 @@ async function handler(ctx) {
item = $(item);

return {
link: new URL(item.attr('href'), rootUrl).href,
link: new URL(item.prop('href'), rootUrl).href,
};
});

items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
const { data: detailResponse } = await got(item.link, {
responseType: 'buffer',
});

const content = load(iconv.decode(detailResponse.data, 'gbk'));

const details = {};
const links = {};
const $$ = load(iconv.decode(detailResponse, 'gbk'));

content('.nex_drama_Details')
.find('em')
.each(function () {
const detail = content(this).parent();
const key = content(this).text();
const value = detail.text().replace(key, '').replaceAll('&nbsp;', '').trim();
if (value) {
details[key.replaceAll(/:|\s/g, '')] = value;
}
});
$$('div.nex_drama_intros em').first().remove();
$$('strong font').each((_, el) => {
el = $$(el);

content('.nex_netdrivelink, .nex_xunleilink').each(function () {
links[content(this).text()] = content(this).next().html();
el.parent().remove();
});

content('.nex_drama_intros em').first().remove();
content('.nex_thread_author_name em').first().remove();
content('.xg1 a').remove();

const matches = content('.nex_drama_Top em')
.text()
.match(/(.*?)(豆瓣:(.*?))/);
const title = $$('div.nex_drama_Top h5').text();
const description = $$('div.nex_drama_intros').html();
const picture =
$$('div.nex_drama_pic')
.html()
.match(/background:url\((.*?)\)/)?.[1] ?? '';

item.title = content('.nex_drama_Top h5').text();
item.author = content('.nex_thread_author_name').text();
item.pubDate = timezone(parseDate(content('.nex_ifpost em').text().replaceAll('发表于', '').trim(), 'YYYY-M-D HH:mm'), +8);
item.category = Object.values(details).map((d) => d.replaceAll('&nbsp;', '').trim());
const details = $$('li.nex_drama_Detail_li, li.nex_drama_Detail_lis dd')
.toArray()
.map((li) => {
li = $$(li);

const key = li.find('em').text().replaceAll(/:|\s/g, '');
const value = li.find('span').length === 0 ? li.contents().last().text().trim() : li.find('span').text().trim();

return { [key]: value };
})
.reduce(
(obj, item) => ({
...obj,
...item,
}),
{}
);

const links =
$$('td.t_f ignore_js_op').length === 0
? $$('td.t_f strong')
.toArray()
.map((l) => {
l = $$(l);

const title = l.contents().first().text();
const link = l.next().prop('href') ?? l.nextUntil('a').next().prop('href');

item.enclosure_url = item.enclosure_url ?? link;
item.enclosure_type = item.enclosure_type ?? 'application/x-bittorrent';
item.enclosure_title = item.enclosure_title ?? title;

return {
title,
tags: l
.contents()
.last()
.text()
.match(/【(.*?)】/g),
link,
};
})
: $$('div.newfujian')
.toArray()
.map((l) => {
l = $$(l);

return {
title: l.find('p.filename').prop('title') || l.find('p.filename').text(),
tags: l
.find('div.fileaq')
.text()
.match(/【(.*?)】/g),
link: l.find('div.down_2 a').prop('href'),
};
});

const pubDateEl = $$('table.boxtable em').first();
const pubDate =
pubDateEl.find('span[title]').length === 0
? pubDateEl
.first()
.text()
.replace(/发表于\s/, '')
: pubDateEl.find('span[title]').prop('title');

item.title = title;
item.description = art(path.join(__dirname, 'templates/description.art'), {
picture: content('.nex_drama_pic')
.html()
.match(/background:url\((.*?)\)/)[1],
name: item.title,
time: matches[1],
score: matches[2],
images: picture
? [
{
src: picture,
alt: title,
},
]
: undefined,
title,
keys: Object.keys(details),
details,
detailKeys: Object.keys(details),
intro: content('.nex_drama_intros').html(),
description,
info: $$('div.nex_drama_sums').html(),
links,
linkKeys: Object.keys(links),
bt: content('.t_f').html(),
info: content('.nex_drama_sums').html(),
});

const magnets = content('.t_f a')
.toArray()
.filter((a) => content(a).attr('href').startsWith('magnet'))
.map((a) => content(a).attr('href'));

if (magnets.length > 0) {
item.enclosure_url = magnets[0];
item.enclosure_type = 'application/x-bittorrent';
}
item.pubDate = timezone(parseDate(pubDate, 'YYYY-M-D HH:mm:ss'), +8);
item.category = Object.values(details)
.flatMap((c) => c.split(/\s/))
.filter(Boolean);
item.author = details['导演'];
item.content = {
html: description,
text: $$('div.nex_drama_intros').text(),
};
item.image = picture;
item.banner = picture;
item.language = language;

return item;
})
)
);

return {
title: `4k世界 - ${$('#fontsearch ul.cl li.a')
.toArray()
.map((a) => $(a).text())
.join('+')}`,
title: `4k世界 - ${
$('#fontsearch ul.cl li.a')
.toArray()
.map((a) => $(a).text())
.join('+') || '不限'
}`,
description: $('meta[name="description"]').prop('content'),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author: $('meta[name="application-name"]').prop('content'),
language,
};
}
Loading

0 comments on commit e3e8ce1

Please sign in to comment.