mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
feat: 使用新接口替换动态详情老接口 (#382)
This commit is contained in:
parent
df3e97d3bf
commit
666c057194
@ -55,131 +55,100 @@ const { log } = utils
|
|||||||
* @property {number} type
|
* @property {number} type
|
||||||
* @property {boolean} hasOfficialLottery 是否官方
|
* @property {boolean} hasOfficialLottery 是否官方
|
||||||
*
|
*
|
||||||
* @param {object} dynamic_detail_card
|
* @param {object} ditem
|
||||||
* @return {UsefulDynamicInfo}
|
* @return {UsefulDynamicInfo}
|
||||||
*/
|
*/
|
||||||
function parseDynamicCard(dynamic_detail_card) {
|
function parseDynamicCard(ditem) {
|
||||||
const { strToJson } = utils;
|
|
||||||
/**临时储存单个动态中的信息 */
|
/**临时储存单个动态中的信息 */
|
||||||
let obj = {};
|
let obj = {};
|
||||||
try {
|
try {
|
||||||
const { desc = {}, card = "{}", extension = {}, extend_json = "{}", display = {} } = dynamic_detail_card
|
const dy_typeenum2num = new Map([
|
||||||
, { is_liked = 1, user_profile = {} } = desc || {}
|
["DYNAMIC_TYPE_FORWARD", 1],
|
||||||
, { info = {} } = user_profile || {}
|
["DYNAMIC_TYPE_DRAW", 2],
|
||||||
, cardToJson = strToJson(card)
|
["DYNAMIC_TYPE_WORD", 4],
|
||||||
, extendjsonToJson = strToJson(extend_json)
|
["DYNAMIC_TYPE_AV", 8],
|
||||||
, { add_on_card_info = [] } = display || {}
|
["DYNAMIC_TYPE_ARTICLE", 64]
|
||||||
, { item = {} } = cardToJson;
|
]);
|
||||||
const dy_type2chat_type = new Map([[1, 17], [2, 11], [4, 17], [8, 1], [64, 12]]);
|
|
||||||
/* 转发者的UID */
|
/* 转发者的UID */
|
||||||
obj.uid = desc.uid
|
obj.uid = ditem?.modules?.module_author?.mid || 0
|
||||||
/* 转发者的name */
|
/* 转发者的name */
|
||||||
obj.uname = info.uname || ''
|
obj.uname = ditem?.modules?.module_author?.name || ''
|
||||||
/* 动态是否点过赞 */
|
/* 动态是否点过赞 */
|
||||||
obj.is_liked = is_liked > 0
|
obj.is_liked = ditem?.modules?.module_stat?.like?.status || false
|
||||||
/* 动态的ts10 */
|
/* 动态的ts10 */
|
||||||
obj.create_time = desc.timestamp
|
obj.create_time = ditem?.modules?.module_author?.pub_ts || 0
|
||||||
/* 动态类型 */
|
/* 动态类型 */
|
||||||
obj.type = desc.type
|
obj.type = dy_typeenum2num.get(ditem?.type) || 0
|
||||||
/* 用于发送评论 */
|
/* 用于发送评论 */
|
||||||
obj.rid_str = desc.rid_str.length > 12 ? desc.dynamic_id_str : desc.rid_str;
|
obj.rid_str = ditem?.basic?.comment_id_str || ""
|
||||||
/* 用于发送评论 */
|
/* 用于发送评论 */
|
||||||
obj.chat_type = dy_type2chat_type.get(obj.type) || 0;
|
obj.chat_type = ditem?.basic?.comment_type || 0
|
||||||
/* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
/* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||||
obj.dynamic_id = desc.dynamic_id_str;
|
obj.dynamic_id = ditem?.id_str || ""
|
||||||
/* 定位@信息 */
|
/* 定位@信息 */
|
||||||
obj.ctrl = (extendjsonToJson.ctrl) || [];
|
obj.ctrl = [];
|
||||||
|
/* 是否有官方抽奖 */
|
||||||
|
obj.hasOfficialLottery = false
|
||||||
|
/* 转发描述 */
|
||||||
|
obj.description = ""
|
||||||
|
let _total_len = 0;
|
||||||
|
ditem?.modules?.module_dynamic?.desc?.rich_text_nodes.forEach(node => {
|
||||||
|
if (node.type === "RICH_TEXT_NODE_TYPE_AT") {
|
||||||
|
obj.ctrl.push({
|
||||||
|
data: node.rid,
|
||||||
|
location: _total_len,
|
||||||
|
length: node.text.length,
|
||||||
|
type: 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/* 是否有官方抽奖 */
|
||||||
|
if (node.type === "RICH_TEXT_NODE_TYPE_LOTTERY") {
|
||||||
|
obj.hasOfficialLottery = true
|
||||||
|
}
|
||||||
|
obj.description += node.orig_text
|
||||||
|
_total_len += node.text.length
|
||||||
|
})
|
||||||
/* 预约抽奖信息 */
|
/* 预约抽奖信息 */
|
||||||
if (add_on_card_info.length > 0) {
|
obj.reserve_id = ditem?.modules?.module_dynamic?.additional?.reserve?.rid || 0
|
||||||
const [status, oid_str, text] = add_on_card_info
|
obj.reserve_lottery_text = ditem?.modules?.module_dynamic?.additional?.reserve?.title || "信息丢失"
|
||||||
.filter(it => typeof it.reserve_attach_card !== 'undefined'
|
/* 充电抽奖 */
|
||||||
&& typeof it.reserve_attach_card.reserve_lottery !== 'undefined'
|
if (ditem?.modules?.module_dynamic?.additional?.type === "ADDITIONAL_TYPE_UPOWER_LOTTERY") {
|
||||||
&& typeof it.reserve_attach_card.reserve_button !== 'undefined')
|
|
||||||
.map(({ reserve_attach_card }) => [
|
|
||||||
reserve_attach_card.reserve_button.status,
|
|
||||||
reserve_attach_card.oid_str,
|
|
||||||
reserve_attach_card.reserve_lottery.text])[0] || [];
|
|
||||||
if (status === 1) {
|
|
||||||
obj.reserve_id = oid_str;
|
|
||||||
obj.reserve_lottery_text = text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (extendjsonToJson[""]) {
|
|
||||||
let r = extendjsonToJson[""].reserve || {};
|
|
||||||
let { reserve_id, reserve_lottery } = r;
|
|
||||||
if (reserve_lottery === 1) {
|
|
||||||
obj.reserve_id = reserve_id + "";
|
|
||||||
obj.reserve_lottery_text = "信息丢失";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (extend_json.match(/"":\{"lottery/)) {
|
|
||||||
obj.is_charge_lottery = true
|
obj.is_charge_lottery = true
|
||||||
}
|
}
|
||||||
/* 是否有官方抽奖 */
|
|
||||||
obj.hasOfficialLottery = extension && extension.lott && true;
|
|
||||||
/* 转发者的描述 纯文字内容 图片动态描述 后两个分别是视频动态的描述和视频本身的描述*/
|
|
||||||
obj.description =
|
|
||||||
(item && ((item.content || '') + (item.description || '')))
|
|
||||||
|| (
|
|
||||||
(cardToJson.dynamic || '')
|
|
||||||
+ (cardToJson.desc || '')
|
|
||||||
+ (cardToJson.vest && cardToJson.vest.content || '')
|
|
||||||
)
|
|
||||||
|| '';
|
|
||||||
/* 转发 */
|
/* 转发 */
|
||||||
if (obj.type === 1) {
|
if (obj.type === 1) {
|
||||||
const { origin_extension = {}, origin = "{}", origin_extend_json = "{}" } = cardToJson
|
|
||||||
, originToJson = strToJson(origin)
|
|
||||||
, { add_on_card_info = [] } = display.origin || {}
|
|
||||||
, originExtendjsonToJson = strToJson(origin_extend_json)
|
|
||||||
, { user = {}, item = {} } = originToJson;
|
|
||||||
/* 源动态的ts10 */
|
|
||||||
obj.origin_create_time = desc.origin.timestamp;
|
|
||||||
/* 被转发者的UID */
|
/* 被转发者的UID */
|
||||||
obj.origin_uid = desc.origin.uid;
|
obj.origin_uid = ditem?.orig?.modules?.module_author?.mid || 0
|
||||||
|
/* 被转发者的name */
|
||||||
|
obj.origin_uname = ditem?.orig?.modules?.module_author?.name || ''
|
||||||
|
/* 源动态的ts10 */
|
||||||
|
obj.origin_create_time = ditem?.orig?.modules?.module_author?.pub_ts || 0
|
||||||
/* 源动态类型 */
|
/* 源动态类型 */
|
||||||
obj.origin_type = desc.orig_type
|
obj.origin_type = dy_typeenum2num.get(ditem?.orig?.type) || 0
|
||||||
/* 被转发者的rid(用于发评论) */
|
/* 被转发者的rid(用于发评论) */
|
||||||
obj.origin_rid_str = desc.origin.rid_str.length > 12 ? desc.origin.dynamic_id_str : desc.origin.rid_str;
|
obj.origin_rid_str = ditem?.orig?.basic?.comment_id_str || ""
|
||||||
/* 用于发送评论 */
|
/* 用于发送评论 */
|
||||||
obj.origin_chat_type = dy_type2chat_type.get(obj.origin_type) || 0
|
obj.origin_chat_type = ditem?.orig?.basic?.comment_type || 0
|
||||||
/* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
/* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||||
obj.origin_dynamic_id = desc.orig_dy_id_str;
|
obj.origin_dynamic_id = ditem?.orig?.id_str || ""
|
||||||
/* 预约抽奖信息 */
|
/* 预约抽奖信息 */
|
||||||
if (add_on_card_info.length > 0) {
|
obj.origin_reserve_id = ditem?.orig?.modules?.module_dynamic?.additional?.reserve?.rid || 0
|
||||||
const [status, oid_str, text] = add_on_card_info
|
obj.origin_reserve_lottery_text = ditem?.orig?.modules?.module_dynamic?.additional?.reserve?.title || "信息丢失"
|
||||||
.filter(it => typeof it.reserve_attach_card !== 'undefined'
|
/* 充电抽奖 */
|
||||||
&& typeof it.reserve_attach_card.reserve_lottery !== 'undefined'
|
if (ditem?.orig?.modules?.module_dynamic?.additional?.type === "ADDITIONAL_TYPE_UPOWER_LOTTERY") {
|
||||||
&& typeof it.reserve_attach_card.reserve_button !== 'undefined')
|
|
||||||
.map(({ reserve_attach_card }) => [
|
|
||||||
reserve_attach_card.reserve_button.status,
|
|
||||||
reserve_attach_card.oid_str,
|
|
||||||
reserve_attach_card.reserve_lottery.text])[0] || [];
|
|
||||||
if (status === 1) {
|
|
||||||
obj.origin_reserve_id = oid_str;
|
|
||||||
obj.origin_reserve_lottery_text = text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (originExtendjsonToJson[""]) {
|
|
||||||
let r = originExtendjsonToJson[""].reserve || {};
|
|
||||||
let { reserve_id, reserve_lottery } = r;
|
|
||||||
if (reserve_lottery === 1) {
|
|
||||||
obj.origin_reserve_id = reserve_id + "";
|
|
||||||
obj.origin_reserve_lottery_text = "信息丢失";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (origin_extend_json.match(/"":\{"lottery/)) {
|
|
||||||
obj.origin_is_charge_lottery = true
|
obj.origin_is_charge_lottery = true
|
||||||
}
|
}
|
||||||
/* 是否有官方抽奖 */
|
/* 是否有官方抽奖 */
|
||||||
obj.origin_hasOfficialLottery = origin_extension && origin_extension.lott;
|
obj.origin_hasOfficialLottery = false
|
||||||
/* 被转发者的name */
|
/* 转发描述 */
|
||||||
obj.origin_uname = (user && (user.name || user.uname)) || '';
|
obj.origin_description = ""
|
||||||
/* 被转发者的描述 */
|
ditem?.orig?.modules?.module_dynamic?.desc?.rich_text_nodes.forEach(node => {
|
||||||
obj.origin_description =
|
/* 是否有官方抽奖 */
|
||||||
(item && (item.content || '' + item.description || ''))
|
if (node.type === "RICH_TEXT_NODE_TYPE_LOTTERY") {
|
||||||
|| (originToJson.dynamic || '' + originToJson.desc || '')
|
obj.origin_hasOfficialLottery = true
|
||||||
|| '';
|
}
|
||||||
|
obj.origin_description += node.orig_text
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("动态卡片解析", e)
|
log.error("动态卡片解析", e)
|
||||||
|
|||||||
@ -5,7 +5,7 @@ module.exports = Object.freeze({
|
|||||||
DYNAMIC_REPOST_SHARE: 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/share',
|
DYNAMIC_REPOST_SHARE: 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/share',
|
||||||
DYNAMIC_SVR_CREATE_DRAW: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create_draw',
|
DYNAMIC_SVR_CREATE_DRAW: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create_draw',
|
||||||
DYNAMIC_SVR_CREATE: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create',
|
DYNAMIC_SVR_CREATE: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create',
|
||||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V: 'https://api.vc.bilibili.com/dynamic_svr/v{{v}}/dynamic_svr/get_dynamic_detail',
|
X_POLYMER_WEB_DYNAMIC_V1_DETAIL: 'https://api.bilibili.com/x/polymer/web-dynamic/v1/detail',
|
||||||
DYNAMIC_SVR_RM_DYNAMIC: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/rm_dynamic',
|
DYNAMIC_SVR_RM_DYNAMIC: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/rm_dynamic',
|
||||||
DYNAMIC_SVR_SPACE_HISTORY: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history',
|
DYNAMIC_SVR_SPACE_HISTORY: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history',
|
||||||
FEED_GET_ATTENTION_LIST: 'https://api.vc.bilibili.com/feed/v1/feed/get_attention_list',
|
FEED_GET_ATTENTION_LIST: 'https://api.vc.bilibili.com/feed/v1/feed/get_attention_list',
|
||||||
|
|||||||
@ -415,39 +415,27 @@ const bili_client = {
|
|||||||
_getOneDynamicByDyid: new Line(
|
_getOneDynamicByDyid: new Line(
|
||||||
'获取一个动态的细节',
|
'获取一个动态的细节',
|
||||||
[
|
[
|
||||||
(dynamic_id) => get({
|
(id) => get({
|
||||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V.replace('{{v}}', 1),
|
url: API.X_POLYMER_WEB_DYNAMIC_V1_DETAIL,
|
||||||
config: { retry: false },
|
config: { retry: false },
|
||||||
query: {
|
query: {
|
||||||
dynamic_id
|
id
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
...Array(10)
|
|
||||||
.fill(
|
|
||||||
(dynamic_id) => get({
|
|
||||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V.replace('{{v}}', Math.floor(Math.random() * 10 ** 10)),
|
|
||||||
config: { retry: false },
|
|
||||||
query: {
|
|
||||||
dynamic_id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
, responseText => {
|
, responseText => {
|
||||||
const
|
const
|
||||||
res = strToJson(responseText),
|
res = strToJson(responseText),
|
||||||
{ code, data } = res,
|
{ code, data } = res,
|
||||||
{ card } = data || {},
|
{ item } = data || {},
|
||||||
{ desc } = card || {};
|
{ id_str } = item || {};
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 0:
|
case 0:
|
||||||
if (card && desc) {
|
if (item && id_str) {
|
||||||
return [false, card, `ok`];
|
return [false, item, `ok`];
|
||||||
} else {
|
} else {
|
||||||
return [false, undefined, `获取动态数据异常:\n${responseText}`];
|
return [false, undefined, `获取动态数据异常:\n${responseText}`];
|
||||||
}
|
}
|
||||||
case 500207:
|
|
||||||
return [false, undefined, `该动态为包月充电专属可以给UP主充电后观看`];
|
|
||||||
default:
|
default:
|
||||||
return [true, undefined, `获取动态数据出错:\n${responseText}`]
|
return [true, undefined, `获取动态数据出错:\n${responseText}`]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user