From e45e7bb46fc06a3cfd4fc945cea4f52729c0cba3 Mon Sep 17 00:00:00 2001
From: DCjanus <46744612+DCJaous@users.noreply.github.com>
Date: Mon, 17 Feb 2020 19:18:02 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20Javlibrary=20?=
=?UTF-8?q?=E6=9C=80=E4=BD=B3=E8=AF=84=E8=AE=BA=20(#4008)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
assets/radar-rules.js | 6 +++++
docs/en/multimedia.md | 4 ++++
docs/multimedia.md | 4 ++++
lib/router.js | 1 +
lib/routes/javlibrary/bestreviews.js | 11 +++++++++
lib/routes/javlibrary/stars.js | 2 +-
lib/routes/javlibrary/userposts.js | 36 ----------------------------
lib/routes/javlibrary/users.js | 14 +++++++----
lib/routes/javlibrary/utils.js | 31 +++++++++++++++++++++++-
lib/routes/javlibrary/videos.js | 2 +-
10 files changed, 68 insertions(+), 43 deletions(-)
create mode 100644 lib/routes/javlibrary/bestreviews.js
delete mode 100644 lib/routes/javlibrary/userposts.js
diff --git a/assets/radar-rules.js b/assets/radar-rules.js
index ddb9a6340b..2b5f9f71ca 100644
--- a/assets/radar-rules.js
+++ b/assets/radar-rules.js
@@ -1152,6 +1152,12 @@
source: '/cn',
target: '/javlibrary/videos/bestrated',
},
+ {
+ title: '最佳评论',
+ docs: 'https://docs.rsshub.app/multimedia.html#javlibrary',
+ source: '/cn',
+ target: '/javlibrary/bestreviews',
+ },
{
title: '影星',
docs: 'https://docs.rsshub.app/multimedia.html#javlibrary',
diff --git a/docs/en/multimedia.md b/docs/en/multimedia.md
index 0fb1bc319e..93303f8b65 100644
--- a/docs/en/multimedia.md
+++ b/docs/en/multimedia.md
@@ -50,6 +50,10 @@ Official RSS: https://eztv.io/ezrss.xml
|userwanted|userwatched|userowned|userposts|
+### Bestreviews
+
+
+
## Nyaa
### Seatch Result
diff --git a/docs/multimedia.md b/docs/multimedia.md
index 51e358a40b..dbb6488321 100644
--- a/docs/multimedia.md
+++ b/docs/multimedia.md
@@ -146,6 +146,10 @@ pageClass: routes
|userwanted|userwatched|userowned|userposts|
+### 最佳评论
+
+
+
## Last.fm
### 用户播放记录
diff --git a/lib/router.js b/lib/router.js
index 5d46b7236f..054d49ccb9 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2210,6 +2210,7 @@ router.get('/netease/ds/:id', require('./routes/netease/ds'));
router.get('/javlibrary/users/:uid/:utype', require('./routes/javlibrary/users'));
router.get('/javlibrary/videos/:vtype', require('./routes/javlibrary/videos'));
router.get('/javlibrary/stars/:sid', require('./routes/javlibrary/stars'));
+router.get('/javlibrary/bestreviews', require('./routes/javlibrary/bestreviews'));
// Last.FM
router.get('/lastfm/recent/:user', require('./routes/lastfm/recent'));
diff --git a/lib/routes/javlibrary/bestreviews.js b/lib/routes/javlibrary/bestreviews.js
new file mode 100644
index 0000000000..2a1f22731a
--- /dev/null
+++ b/lib/routes/javlibrary/bestreviews.js
@@ -0,0 +1,11 @@
+const { getVideoComments } = require('./utils');
+
+module.exports = async (ctx) => {
+ const link = 'http://www.javlibrary.com/cn/tl_bestreviews.php';
+ const items = await getVideoComments(link);
+ ctx.state.data = {
+ title: 'Javlibrary - 最佳评论',
+ link: link,
+ item: items,
+ };
+};
diff --git a/lib/routes/javlibrary/stars.js b/lib/routes/javlibrary/stars.js
index 34c581fa06..c4ae433bb0 100644
--- a/lib/routes/javlibrary/stars.js
+++ b/lib/routes/javlibrary/stars.js
@@ -1,4 +1,4 @@
-const template = require('./utils');
+const { template } = require('./utils');
module.exports = async (ctx) => {
const sid = ctx.params.sid;
diff --git a/lib/routes/javlibrary/userposts.js b/lib/routes/javlibrary/userposts.js
deleted file mode 100644
index 06a00c4c66..0000000000
--- a/lib/routes/javlibrary/userposts.js
+++ /dev/null
@@ -1,36 +0,0 @@
-const cheerio = require('cheerio');
-const dateUtil = require('@/utils/date');
-const cloudscraper = require('cloudscraper');
-
-module.exports = async (ctx) => {
- const uid = ctx.params.uid;
- const link = `http://www.javlibrary.com/cn/userposts.php?u=${uid}`;
- const response = await cloudscraper.get(link);
- const $ = cheerio.load(response);
- const list = $('#video_comments > table');
-
- ctx.state.data = {
- title: `Javlibrary - ${uid} 发表的文章`,
- link: link,
- item:
- list &&
- list
- .map((index, item) => {
- item = $(item);
- // 文章内容只能抓取到 td.t textarea,若含有图片则替换[img]image-link[/img] =>
- let comments = item.find('textarea').text();
- comments = comments.replace(new RegExp('\\[img\\]', 'g'), '
');
- return {
- title: item.find('tbody > tr:nth-child(1) > td:nth-child(2)').text(),
- link: item.find('tbody > tr:nth-child(1) > td:nth-child(2) > a').attr('href'),
- description: `
-
- | ${item.find('tbody > tr:nth-child(1) > td:nth-child(2)').html()} |
- | ${comments} |
-
`,
- pubDate: dateUtil(item.find('tbody > tr:nth-child(3) > td.date')),
- };
- })
- .get(),
- };
-};
diff --git a/lib/routes/javlibrary/users.js b/lib/routes/javlibrary/users.js
index 6328a4a127..9f03b8a010 100644
--- a/lib/routes/javlibrary/users.js
+++ b/lib/routes/javlibrary/users.js
@@ -1,12 +1,18 @@
-const template = require('./utils');
-const userposts = require('./userposts');
+const { template, getVideoComments } = require('./utils');
+
module.exports = async (ctx) => {
const utype = ctx.params.utype;
const uid = ctx.params.uid;
- // userposts 页面结构不同,单独写路由
if (utype === 'userposts') {
- await userposts(ctx);
+ const uid = ctx.params.uid;
+ const link = `http://www.javlibrary.com/cn/userposts.php?u=${uid}`;
+ const items = await getVideoComments(link);
+ ctx.state.data = {
+ title: `Javlibrary - ${uid} 发表的文章`,
+ link: link,
+ item: items,
+ };
} else {
ctx.state.data = {
link: `http://www.javlibrary.com/cn/${utype}.php?u=${uid}`,
diff --git a/lib/routes/javlibrary/utils.js b/lib/routes/javlibrary/utils.js
index 9bbb32c594..dbef298c36 100644
--- a/lib/routes/javlibrary/utils.js
+++ b/lib/routes/javlibrary/utils.js
@@ -1,9 +1,10 @@
const url = require('url');
const cheerio = require('cheerio');
const cloudscraper = require('cloudscraper');
+const dateUtil = require('@/utils/date');
// 通过传入不同的ctx.state.data.link 返回javlibrary 不同link的rss
-module.exports = async function template(ctx) {
+exports.template = async function template(ctx) {
const link = ctx.state.data.link;
const response = await cloudscraper.get(link);
const $ = cheerio.load(response);
@@ -37,3 +38,31 @@ module.exports = async function template(ctx) {
item: items,
};
};
+
+exports.getVideoComments = async function getVideoComments(link) {
+ const response = await cloudscraper.get(link);
+ const $ = cheerio.load(response);
+ const list = $('#video_comments > table');
+
+ return (
+ list &&
+ list
+ .map((index, item) => {
+ item = $(item);
+ // 文章内容只能抓取到 td.t textarea,若含有图片则替换[img]image-link[/img] =>
+ let comments = item.find('textarea').text();
+ comments = comments.replace(new RegExp('\\[img\\]', 'g'), '
');
+ return {
+ title: item.find('tbody > tr:nth-child(1) > td:nth-child(2)').text(),
+ link: item.find('tbody > tr:nth-child(1) > td:nth-child(2) > a').attr('href'),
+ description: `
+
+ | ${item.find('tbody > tr:nth-child(1) > td:nth-child(2)').html()} |
+ | ${comments} |
+
`,
+ pubDate: dateUtil(item.find('tbody > tr:nth-child(3) > td.date')),
+ };
+ })
+ .get()
+ );
+};
diff --git a/lib/routes/javlibrary/videos.js b/lib/routes/javlibrary/videos.js
index fa8c1b374e..15488c724c 100644
--- a/lib/routes/javlibrary/videos.js
+++ b/lib/routes/javlibrary/videos.js
@@ -1,4 +1,4 @@
-const template = require('./utils');
+const { template } = require('./utils');
module.exports = async (ctx) => {
const vtype = ctx.params.vtype;