From aaef7c73eda192e1f70b2323b48ea0df69c52b69 Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Mon, 12 Jun 2023 19:50:08 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=204k=E4=B8=96=E7=95=8C=20(#1?=
=?UTF-8?q?2654)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/multimedia.md | 16 ++++
lib/v2/4ksj/forum.js | 128 ++++++++++++++++++++++++++
lib/v2/4ksj/maintainer.js | 3 +
lib/v2/4ksj/radar.js | 13 +++
lib/v2/4ksj/router.js | 3 +
lib/v2/4ksj/templates/description.art | 56 +++++++++++
6 files changed, 219 insertions(+)
create mode 100644 lib/v2/4ksj/forum.js
create mode 100644 lib/v2/4ksj/maintainer.js
create mode 100644 lib/v2/4ksj/radar.js
create mode 100644 lib/v2/4ksj/router.js
create mode 100644 lib/v2/4ksj/templates/description.art
diff --git a/docs/multimedia.md b/docs/multimedia.md
index 0c9c6d32d..0b19f4e0b 100644
--- a/docs/multimedia.md
+++ b/docs/multimedia.md
@@ -144,6 +144,22 @@ pageClass: routes
+## 4k 世界
+
+### 分类
+
+
+
+::: tip 提示
+
+若订阅 [最新4K电影](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)。
+
+若订阅子分类 [Dolby Vision纪录片4K电影](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)。
+
+:::
+
+
+
## 60-Second Science - Scientific American
diff --git a/lib/v2/4ksj/forum.js b/lib/v2/4ksj/forum.js
new file mode 100644
index 000000000..c9fa7f8c0
--- /dev/null
+++ b/lib/v2/4ksj/forum.js
@@ -0,0 +1,128 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const timezone = require('@/utils/timezone');
+const { parseDate } = require('@/utils/parse-date');
+const { art } = require('@/utils/render');
+const path = require('path');
+const iconv = require('iconv-lite');
+
+module.exports = async (ctx) => {
+ const id = ctx.params.id ?? '2-1';
+ const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 25;
+
+ const rootUrl = 'https://www.4ksj.com';
+ const currentUrl = `${rootUrl}/forum-${id}.html`;
+
+ const response = await got({
+ method: 'get',
+ url: currentUrl,
+ responseType: 'buffer',
+ });
+
+ const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
+
+ let items = $('div.nex_cmo_piv a')
+ .slice(0, limit)
+ .toArray()
+ .map((item) => {
+ item = $(item);
+
+ return {
+ link: new URL(item.attr('href'), rootUrl).href,
+ };
+ });
+
+ items = await Promise.all(
+ items.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const detailResponse = await got({
+ method: 'get',
+ url: item.link,
+ responseType: 'buffer',
+ });
+
+ const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk'));
+
+ const details = {};
+ const links = {};
+
+ content('.nex_drama_Details')
+ .find('em')
+ .each(function () {
+ const detail = content(this).parent();
+ const key = content(this).text();
+ const value = detail
+ .text()
+ .replace(key, '')
+ .replace(/ /g, '')
+ .trim();
+ if (value) {
+ details[key.replace(/:|\s/g, '')] = value;
+ }
+ });
+
+ content('.nex_netdrivelink, .nex_xunleilink').each(function () {
+ links[content(this).text()] = content(this).next().html();
+ });
+
+ 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(/(.*?)(豆瓣:(.*?))/);
+
+ 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()
+ .replace(/发表于/g, '')
+ .trim(),
+ 'YYYY-M-D HH:mm'
+ ),
+ +8
+ );
+ item.category = Object.values(details).map((d) => d.replace(/ /g, '').trim());
+ 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],
+ details,
+ detailKeys: Object.keys(details),
+ intro: content('.nex_drama_intros').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) => /^magnet/.test(content(a).attr('href')))
+ .map((a) => content(a).attr('href'));
+
+ if (magnets.length > 0) {
+ item.enclosure_url = magnets[0];
+ item.enclosure_type = 'application/x-bittorrent';
+ }
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: `4k世界 - ${$('#fontsearch ul.cl li.a')
+ .toArray()
+ .map((a) => $(a).text())
+ .join('+')}`,
+ link: currentUrl,
+ item: items,
+ };
+};
diff --git a/lib/v2/4ksj/maintainer.js b/lib/v2/4ksj/maintainer.js
new file mode 100644
index 000000000..e53818675
--- /dev/null
+++ b/lib/v2/4ksj/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/forum/:id?': ['nczitzk'],
+};
diff --git a/lib/v2/4ksj/radar.js b/lib/v2/4ksj/radar.js
new file mode 100644
index 000000000..993f0e4a8
--- /dev/null
+++ b/lib/v2/4ksj/radar.js
@@ -0,0 +1,13 @@
+module.exports = {
+ '4ksj.com': {
+ _name: '4k 世界',
+ '.': [
+ {
+ title: '分类',
+ docs: 'https://docs.rsshub.app/multimedia.html#4k-shi-jie-fen-lei',
+ source: ['/forum-2-1.html', '/'],
+ target: (params, url) => `/4ksj/forum/${new URL(url).href.match(/\/forum-([\w-]+)\.html/)[1]}`,
+ },
+ ],
+ },
+};
diff --git a/lib/v2/4ksj/router.js b/lib/v2/4ksj/router.js
new file mode 100644
index 000000000..6d2c00761
--- /dev/null
+++ b/lib/v2/4ksj/router.js
@@ -0,0 +1,3 @@
+module.exports = function (router) {
+ router.get('/forum/:id?', require('./forum'));
+};
diff --git a/lib/v2/4ksj/templates/description.art b/lib/v2/4ksj/templates/description.art
new file mode 100644
index 000000000..8b4f8f609
--- /dev/null
+++ b/lib/v2/4ksj/templates/description.art
@@ -0,0 +1,56 @@
+{{ if picture }}
+
+{{ /if }}
+
+{{ if details }}
+
+
+
+ | 片名 |
+ {{ name }} |
+
+
+ | 时间 |
+ {{ time }} |
+
+
+ | 豆瓣评分 |
+ {{ score }} |
+
+ {{ each detailKeys detail }}
+
+ | {{ detail }} |
+ {{@ details[detail] }} |
+
+ {{ /each }}
+
+
+{{ /if }}
+
+简介
+ {{@ intro }}
+
+
+网盘下载
+{{ if links }}
+
+
+ {{ each linkKeys link }}
+
+ | {{ link }} |
+ {{@ links[link] }} |
+
+ {{ /each }}
+
+
+{{ /if }}
+
+
+BT种子 / 磁力链下载
+{{@ bt }}
+
+
+影片信息
+{{ if info }}
+{{@ info }}
+{{ /if }}
\ No newline at end of file