feat: add 新榜(newrank.cn) (#5254)
This commit is contained in:
@@ -506,3 +506,8 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
|
||||
- `BTBYR_HOST`: 支持 ipv4 访问的 BTBYR 镜像,默认为原站 `https://bt.byr.cn/`。
|
||||
|
||||
- `BTBYR_COOKIE`: 注册用户登录后的 Cookie 值,获取方式:1. 登录后打开网站首页 2. 打开控制台 3. 刷新 4. 找到 <https://bt.byr.cn/index.php> 请求 5. 找到请求头中的 Cookie
|
||||
|
||||
- 新榜
|
||||
|
||||
- `NEWRANK_USERNAME`: 用户名
|
||||
- `NEWRANK_PASSWORD`: 密码
|
||||
|
||||
@@ -840,6 +840,24 @@ rule
|
||||
|
||||
<Route author="lotosbin" example="/xiaohongshu/board/5db6f79200000000020032df" path="/xiaohongshu/board/:board_id" :paramsDesc="['board_id']" />
|
||||
|
||||
## 新榜
|
||||
|
||||
::: warning 注意
|
||||
部署时需要配置 NEWRANK_USERNAME、NEWRANK_PASSWORD,具体见部署文档
|
||||
:::
|
||||
|
||||
### 微信公众号
|
||||
|
||||
<Route author="BossDoge" example="/newrank/wechat/chijiread" path="/newrank/wechat/:wxid" :paramsDesc="['微信号,若微信号与新榜信息不一致,以新榜为准']" anticrawler="1"/>
|
||||
|
||||
### 抖音短视频
|
||||
|
||||
<Route author="BossDoge" example="/newrank/douyin/110266463747" path="/newrank/douyin/:dyid" :paramsDesc="['抖音ID,可在新榜账号详情 URL 中找到']" anticrawler="1"/>
|
||||
|
||||
::: warning 注意
|
||||
免费版账户抖音每天查询次数20次,如需增加次数可购买新榜会员或等待未来多账户支持
|
||||
:::
|
||||
|
||||
## 知乎
|
||||
|
||||
### 收藏夹
|
||||
|
||||
@@ -144,6 +144,10 @@ const calculateValue = () => {
|
||||
host: envs.BTBYR_HOST || 'https://bt.byr.cn/',
|
||||
cookies: envs.BTBYR_COOKIE,
|
||||
},
|
||||
newrank: {
|
||||
username: envs.NEWRANK_USERNAME,
|
||||
password: envs.NEWRANK_PASSWORD,
|
||||
},
|
||||
};
|
||||
};
|
||||
calculateValue();
|
||||
|
||||
@@ -2971,6 +2971,10 @@ router.get('/ngbj/cat/:cat', require('./routes/niaogebiji/cat'));
|
||||
// 东方我乐多丛志
|
||||
router.get('/touhougarakuta/:language/:type', require('./routes/touhougarakuta'));
|
||||
|
||||
// 新榜
|
||||
router.get('/newrank/wechat/:wxid', require('./routes/newrank/wechat'));
|
||||
router.get('/newrank/douyin/:dyid', require('./routes/newrank/douyin'));
|
||||
|
||||
// 漫小肆
|
||||
router.get('/manxiaosi/book/:id', require('./routes/manxiaosi/book'));
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
const got = require('@/utils/got');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const uid = ctx.params.dyid;
|
||||
const nonce = utils.random_nonce(9);
|
||||
const url_detail = 'https://xd.newrank.cn/xdnphb/nr/cloud/douyin/detail/aweme?xyz=' + utils.decrypt_douyin_detail_xyz(nonce) + '&nonce=' + nonce;
|
||||
const cookie = await utils.getCookie(ctx);
|
||||
const response_detail = await got({
|
||||
method: 'post',
|
||||
url: url_detail,
|
||||
headers: {
|
||||
Connection: 'keep-alive',
|
||||
Cookie: cookie,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: JSON.stringify({
|
||||
create_time_end: '',
|
||||
create_time_start: '',
|
||||
date_type: '',
|
||||
is_promotion: '0',
|
||||
is_seed: '0',
|
||||
keyword: '',
|
||||
size: 20,
|
||||
sort: 'create_time',
|
||||
start: 1,
|
||||
uid: uid,
|
||||
}),
|
||||
});
|
||||
const url_account = 'https://xd.newrank.cn/xdnphb/nr/cloud/douyin/detail/accountInfoAll?nonce=' + nonce + '&xyz=' + utils.decrypt_douyin_account_xyz(nonce);
|
||||
const response_account = await got({
|
||||
method: 'post',
|
||||
url: url_account,
|
||||
headers: {
|
||||
Connection: 'keep-alive',
|
||||
Cookie: cookie,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: JSON.stringify({
|
||||
uid: uid,
|
||||
}),
|
||||
});
|
||||
const name = response_account.data.data.nickname;
|
||||
const description = response_account.data.data.signature;
|
||||
const articles = utils.flatten(response_detail.data.data.list);
|
||||
const items = await Promise.all(
|
||||
articles.map(async (item) => ({
|
||||
title: item.aweme_desc,
|
||||
description: '',
|
||||
link: item.share_url,
|
||||
pubDate: item.create_time,
|
||||
}))
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: name + ' - 抖音',
|
||||
description: description,
|
||||
link: 'https://xd.newrank.cn/data/d/account/workList/' + uid,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
const md5 = require('@/utils/md5');
|
||||
const got = require('@/utils/got');
|
||||
const config = require('@/config').value;
|
||||
const newrank_cookie_token = 'newrank_cookie_token';
|
||||
const query_count = 'newrank_cookie_count';
|
||||
const max_query_count = 30;
|
||||
|
||||
const random_nonce = (count) => {
|
||||
const arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
|
||||
const shuffled = arr.slice(0);
|
||||
let i = arr.length,
|
||||
temp,
|
||||
index,
|
||||
str = '';
|
||||
const min = i - count;
|
||||
while (i-- > min) {
|
||||
index = Math.floor((i + 1) * Math.random());
|
||||
temp = shuffled[index];
|
||||
str = str + temp;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const decrypt_login_xyz = (username, decrypt_password, nonce) => {
|
||||
const str = '/nr/user/login/loginByAccount?AppKey=joker&account=' + username + '&password=' + decrypt_password + '&state=1&nonce=' + nonce;
|
||||
return md5(str);
|
||||
};
|
||||
|
||||
const decrypt_wechat_detail_xyz = (uid, nonce) => {
|
||||
const str = '/xdnphb/detail/v1/rank/article/lists?AppKey=joker&account=' + uid + '&nonce=' + nonce;
|
||||
return md5(str);
|
||||
};
|
||||
|
||||
const decrypt_douyin_account_xyz = (nonce) => {
|
||||
const str = '/xdnphb/nr/cloud/douyin/detail/accountInfoAll?AppKey=joker&nonce=' + nonce;
|
||||
return md5(str);
|
||||
};
|
||||
|
||||
const decrypt_douyin_detail_xyz = (nonce) => {
|
||||
const str = '/xdnphb/nr/cloud/douyin/detail/aweme?AppKey=joker&nonce=' + nonce;
|
||||
return md5(str);
|
||||
};
|
||||
|
||||
const flatten = (arr) => arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), []);
|
||||
|
||||
async function shouldUpdateCookie(ctx, forcedUpdate = false) {
|
||||
if (forcedUpdate) {
|
||||
ctx.cache.set(query_count, 0);
|
||||
} else {
|
||||
const count = ctx.cache.get(query_count);
|
||||
if (!count) {
|
||||
ctx.cache.set(query_count, 1);
|
||||
} else {
|
||||
if (count > max_query_count) {
|
||||
ctx.cache.set(query_count, 0);
|
||||
await clearCookie(ctx);
|
||||
} else {
|
||||
ctx.cache.set(query_count, count + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function clearCookie(ctx) {
|
||||
ctx.cache.set(newrank_cookie_token, null);
|
||||
}
|
||||
|
||||
async function getCookie(ctx) {
|
||||
// Check if this key should be replace? every 30 times should be fine.
|
||||
await shouldUpdateCookie(ctx);
|
||||
let token = await ctx.cache.get(newrank_cookie_token);
|
||||
const username = config.newrank.username;
|
||||
const password = md5(md5(config.newrank.password) + 'daddy');
|
||||
const nonce = random_nonce(9);
|
||||
const xyz = decrypt_login_xyz(username, password, nonce);
|
||||
if (!token) {
|
||||
const indexResponse = await got({
|
||||
method: 'post',
|
||||
url: 'https://www.newrank.cn/nr/user/login/loginByAccount',
|
||||
form: {
|
||||
account: username,
|
||||
password: password,
|
||||
state: 1,
|
||||
nonce: nonce,
|
||||
xyz: xyz,
|
||||
},
|
||||
});
|
||||
const set_cookie = indexResponse.headers['set-cookie'];
|
||||
if (set_cookie) {
|
||||
for (const e of set_cookie) {
|
||||
if (e.indexOf('token') === 0) {
|
||||
token = e.split(';')[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.cache.set(newrank_cookie_token, token, 600);
|
||||
// We have acquired new cookie. It may due to cache timeout.
|
||||
// Force update counter and don't wait it finished.
|
||||
shouldUpdateCookie(ctx, true);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getCookie,
|
||||
random_nonce,
|
||||
decrypt_wechat_detail_xyz,
|
||||
decrypt_douyin_account_xyz,
|
||||
decrypt_douyin_detail_xyz,
|
||||
flatten,
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
const got = require('@/utils/got');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const uid = ctx.params.wxid;
|
||||
const nonce = utils.random_nonce(9);
|
||||
const response = await got({
|
||||
method: 'post',
|
||||
url: 'https://www.newrank.cn/xdnphb/detail/v1/rank/article/lists',
|
||||
headers: {
|
||||
Connection: 'keep-alive',
|
||||
Cookie: await utils.getCookie(ctx),
|
||||
},
|
||||
form: {
|
||||
account: uid,
|
||||
nonce: nonce,
|
||||
xyz: utils.decrypt_wechat_detail_xyz(uid, nonce),
|
||||
},
|
||||
});
|
||||
const name = response.data.value.user.name;
|
||||
const articles = utils.flatten(response.data.value.articles);
|
||||
const items = await Promise.all(
|
||||
articles.map(async (item) => ({
|
||||
title: item.title,
|
||||
description: '',
|
||||
link: item.url,
|
||||
pubDate: item.publicTime,
|
||||
}))
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: name + ' - 微信公众号',
|
||||
link: 'https://www.newrank.cn/new/readDetial?account=' + uid,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user