Merge pull request #15031 from CaoMeiYouRen/fix/bilibili/user/dynamic-v2
fix(route): 迁移 bilibili 用户动态路由到新版 web 路由
This commit is contained in:
+484
@@ -0,0 +1,484 @@
|
||||
interface Likeicon {
|
||||
action_url: string;
|
||||
end_url: string;
|
||||
id: number;
|
||||
start_url: string;
|
||||
}
|
||||
interface Basic {
|
||||
comment_id_str: string;
|
||||
comment_type: number;
|
||||
jump_url?: string;
|
||||
like_icon: Likeicon;
|
||||
rid_str: string;
|
||||
}
|
||||
interface Containersize {
|
||||
height: number;
|
||||
width: number;
|
||||
}
|
||||
interface Posspec {
|
||||
axis_x: number;
|
||||
axis_y: number;
|
||||
coordinate_pos: number;
|
||||
}
|
||||
interface Renderspec {
|
||||
opacity: number;
|
||||
}
|
||||
interface Generalspec {
|
||||
pos_spec: Posspec;
|
||||
render_spec: Renderspec;
|
||||
size_spec: Containersize;
|
||||
}
|
||||
interface AVATARLAYER {}
|
||||
interface Webcssstyle {
|
||||
borderRadius: string;
|
||||
'background-color'?: string;
|
||||
border?: string;
|
||||
boxSizing?: string;
|
||||
}
|
||||
interface Generalconfig {
|
||||
web_css_style: Webcssstyle;
|
||||
}
|
||||
interface GENERALCFG {
|
||||
config_type: number;
|
||||
general_config: Generalconfig;
|
||||
}
|
||||
interface Tags {
|
||||
AVATAR_LAYER?: AVATARLAYER;
|
||||
GENERAL_CFG: GENERALCFG;
|
||||
ICON_LAYER?: AVATARLAYER;
|
||||
}
|
||||
interface Layerconfig {
|
||||
is_critical?: boolean;
|
||||
tags: Tags;
|
||||
}
|
||||
interface Remote {
|
||||
bfs_style: string;
|
||||
url: string;
|
||||
}
|
||||
interface Imagesrc {
|
||||
placeholder?: number;
|
||||
remote?: Remote;
|
||||
src_type: number;
|
||||
local?: number;
|
||||
}
|
||||
interface Resimage {
|
||||
image_src: Imagesrc;
|
||||
}
|
||||
interface Resource {
|
||||
res_image: Resimage;
|
||||
res_type: number;
|
||||
}
|
||||
interface Layer {
|
||||
general_spec: Generalspec;
|
||||
layer_config: Layerconfig;
|
||||
resource: Resource;
|
||||
visible: boolean;
|
||||
}
|
||||
interface Fallbacklayers {
|
||||
is_critical_group: boolean;
|
||||
layers: Layer[];
|
||||
}
|
||||
interface Avatar {
|
||||
container_size: Containersize;
|
||||
fallback_layers: Fallbacklayers;
|
||||
mid: string;
|
||||
}
|
||||
interface Fan {
|
||||
color: string;
|
||||
is_fan: boolean;
|
||||
num_str: string;
|
||||
number: number;
|
||||
}
|
||||
interface Decorate {
|
||||
card_url: string;
|
||||
fan: Fan;
|
||||
id: number;
|
||||
jump_url: string;
|
||||
name: string;
|
||||
type: number;
|
||||
}
|
||||
interface Officialverify {
|
||||
desc: string;
|
||||
type: number;
|
||||
}
|
||||
interface Pendant {
|
||||
expire: number;
|
||||
image: string;
|
||||
image_enhance: string;
|
||||
image_enhance_frame: string;
|
||||
n_pid: number;
|
||||
name: string;
|
||||
pid: number;
|
||||
}
|
||||
interface Label {
|
||||
bg_color: string;
|
||||
bg_style: number;
|
||||
border_color: string;
|
||||
img_label_uri_hans: string;
|
||||
img_label_uri_hans_static: string;
|
||||
img_label_uri_hant: string;
|
||||
img_label_uri_hant_static: string;
|
||||
label_theme: string;
|
||||
path: string;
|
||||
text: string;
|
||||
text_color: string;
|
||||
use_img_label: boolean;
|
||||
}
|
||||
interface Vip {
|
||||
avatar_subscript: number;
|
||||
avatar_subscript_url: string;
|
||||
due_date: number;
|
||||
label: Label;
|
||||
nickname_color: string;
|
||||
status: number;
|
||||
theme_type: number;
|
||||
type: number;
|
||||
}
|
||||
interface Moduleauthor {
|
||||
avatar: Avatar;
|
||||
decorate?: Decorate;
|
||||
face: string;
|
||||
face_nft: boolean;
|
||||
following: boolean;
|
||||
jump_url: string;
|
||||
label: string;
|
||||
mid: number;
|
||||
name: string;
|
||||
official_verify: Officialverify;
|
||||
pendant: Pendant;
|
||||
pub_action: string;
|
||||
pub_location_text?: string;
|
||||
pub_time: string;
|
||||
pub_ts: number;
|
||||
type: AuthorType;
|
||||
vip: Vip;
|
||||
}
|
||||
interface Jumpstyle {
|
||||
icon_url: string;
|
||||
text: string;
|
||||
}
|
||||
interface Button {
|
||||
jump_style: Jumpstyle;
|
||||
jump_url: string;
|
||||
type: number;
|
||||
}
|
||||
|
||||
interface Common {
|
||||
button: Button;
|
||||
cover: string;
|
||||
desc1: string;
|
||||
desc2: string;
|
||||
head_text: string;
|
||||
id_str: string;
|
||||
jump_url: string;
|
||||
style: number;
|
||||
sub_type: string;
|
||||
title: string;
|
||||
}
|
||||
interface Additional {
|
||||
common: Common;
|
||||
type: string;
|
||||
}
|
||||
interface Richtextnode {
|
||||
orig_text: string;
|
||||
rid?: string;
|
||||
text: string;
|
||||
type: string;
|
||||
jump_url?: string;
|
||||
emoji?: Emoji;
|
||||
}
|
||||
interface Desc {
|
||||
rich_text_nodes: Richtextnode[];
|
||||
text: string;
|
||||
}
|
||||
interface Pic {
|
||||
height: number;
|
||||
size: number;
|
||||
url: string;
|
||||
width: number;
|
||||
}
|
||||
interface Opus {
|
||||
fold_action: string[];
|
||||
jump_url: string;
|
||||
pics: Pic[];
|
||||
summary: Desc;
|
||||
title?: string;
|
||||
}
|
||||
interface Badge {
|
||||
bg_color: string;
|
||||
color: string;
|
||||
icon_url?: string;
|
||||
text: string;
|
||||
}
|
||||
interface Stat {
|
||||
danmaku: string;
|
||||
play: string;
|
||||
}
|
||||
interface Pgc {
|
||||
badge: Badge;
|
||||
cover: string;
|
||||
epid: number;
|
||||
jump_url: string;
|
||||
season_id: number;
|
||||
stat: Stat;
|
||||
stat_hidden: number;
|
||||
sub_type: number;
|
||||
title: string;
|
||||
type: number;
|
||||
}
|
||||
interface Live {
|
||||
badge: Badge;
|
||||
cover: string;
|
||||
desc_first: string;
|
||||
desc_second: string;
|
||||
id: number;
|
||||
jump_url: string;
|
||||
live_state: number;
|
||||
reserve_type: number;
|
||||
title: string;
|
||||
}
|
||||
interface Common2 {
|
||||
badge: Badge;
|
||||
biz_type: number;
|
||||
cover: string;
|
||||
desc: string;
|
||||
id: string;
|
||||
jump_url: string;
|
||||
label: string;
|
||||
sketch_id: string;
|
||||
style: number;
|
||||
title: string;
|
||||
}
|
||||
interface Archive {
|
||||
aid: string;
|
||||
badge: Badge;
|
||||
bvid: string;
|
||||
cover: string;
|
||||
desc: string;
|
||||
disable_preview: number;
|
||||
duration_text: string;
|
||||
jump_url: string;
|
||||
stat: Stat;
|
||||
title: string;
|
||||
type: number;
|
||||
}
|
||||
interface UgcSeason {
|
||||
aid: number; // 视频AV号
|
||||
badge: Badge; // 角标信息
|
||||
cover: string; // 视频封面
|
||||
desc: string; // 视频简介
|
||||
disable_preview: number; // 0
|
||||
duration_text: string; // 时长
|
||||
jump_url: string; // 跳转URL
|
||||
stat: Stat; // 统计信息
|
||||
title: string; // 视频标题
|
||||
}
|
||||
|
||||
interface Article {
|
||||
covers: string[]; // 封面图数组,最多三张
|
||||
desc: string; // 文章摘要
|
||||
id: number; // 文章CV号
|
||||
jump_url: string; // 文章跳转地址
|
||||
label: string; // 文章阅读量
|
||||
title: string; // 文章标题
|
||||
}
|
||||
|
||||
interface DrawItem {
|
||||
height: number; // 图片高度
|
||||
size: number; // 图片大小,单位KB
|
||||
src: string; // 图片URL
|
||||
tags: any[]; // 标签数组
|
||||
width: number; // 图片宽度
|
||||
}
|
||||
|
||||
interface Draw {
|
||||
id: number; // 对应相簿id
|
||||
items: DrawItem[]; // 图片信息列表
|
||||
}
|
||||
|
||||
interface LiveRcmd {
|
||||
content: string; // 直播间内容JSON
|
||||
reserve_type: number; // 0
|
||||
}
|
||||
|
||||
interface Course {
|
||||
badge: Badge; // 角标信息
|
||||
cover: string; // 封面图URL
|
||||
desc: string; // 更新状态描述
|
||||
id: number; // 课程id
|
||||
jump_url: string; // 跳转URL
|
||||
sub_title: string; // 课程副标题
|
||||
title: string; // 课程标题
|
||||
}
|
||||
|
||||
interface Music {
|
||||
cover: string; // 音频封面
|
||||
id: number; // 音频AUID
|
||||
jump_url: string; // 跳转URL
|
||||
label: string; // 音频分类
|
||||
title: string; // 音频标题
|
||||
}
|
||||
|
||||
interface None {
|
||||
tips: string; // 动态失效显示文案
|
||||
}
|
||||
|
||||
interface Major {
|
||||
type: MajorType;
|
||||
ugc_season?: UgcSeason; // 合集信息
|
||||
article?: Article; // 专栏
|
||||
draw?: Draw; // 带图动态
|
||||
archive?: Archive; // 视频信息
|
||||
live_rcmd?: LiveRcmd; // 直播状态
|
||||
common?: Common2; // 一般类型
|
||||
opus?: Opus; // 图文动态
|
||||
pgc?: Pgc; // 剧集信息
|
||||
courses?: Course; // 课程信息
|
||||
music?: Music; // 音频信息
|
||||
live?: Live; // 直播信息
|
||||
none?: None; // 动态失效
|
||||
}
|
||||
interface Topic {
|
||||
id: number; // 话题id
|
||||
jump_url: string; // 跳转URL
|
||||
name: string; // 话题名称
|
||||
}
|
||||
|
||||
interface Moduledynamic {
|
||||
additional?: Additional;
|
||||
desc?: Desc;
|
||||
major?: Major;
|
||||
topic?: Topic;
|
||||
}
|
||||
interface Emoji {
|
||||
icon_url: string;
|
||||
size: number;
|
||||
text: string;
|
||||
type: number;
|
||||
}
|
||||
|
||||
interface Item {
|
||||
desc: Desc;
|
||||
type: number;
|
||||
}
|
||||
interface Moduleinteraction {
|
||||
items: Item[];
|
||||
}
|
||||
interface Threepointitem {
|
||||
label: string;
|
||||
type: string;
|
||||
}
|
||||
interface Modulemore {
|
||||
three_point_items: Threepointitem[];
|
||||
}
|
||||
interface Comment {
|
||||
count: number;
|
||||
forbidden: boolean;
|
||||
}
|
||||
interface Like {
|
||||
count: number;
|
||||
forbidden: boolean;
|
||||
status: boolean;
|
||||
}
|
||||
interface Modulestat {
|
||||
comment: Comment;
|
||||
forward: Comment;
|
||||
like: Like;
|
||||
}
|
||||
interface Moduletag {
|
||||
text: string;
|
||||
}
|
||||
interface Modules {
|
||||
module_author?: Moduleauthor;
|
||||
module_dynamic?: Moduledynamic;
|
||||
module_interaction?: Moduleinteraction;
|
||||
module_more?: Modulemore;
|
||||
module_stat?: Modulestat;
|
||||
module_tag?: Moduletag;
|
||||
}
|
||||
|
||||
export interface Orig {
|
||||
basic: Basic;
|
||||
id_str: string;
|
||||
modules: Modules;
|
||||
type: DynamicType;
|
||||
visible: boolean;
|
||||
}
|
||||
export interface Item2 {
|
||||
basic: Basic;
|
||||
id_str: string;
|
||||
modules: Modules;
|
||||
type: DynamicType;
|
||||
visible: boolean;
|
||||
orig?: Orig;
|
||||
}
|
||||
export interface Data {
|
||||
has_more: boolean;
|
||||
items: Item2[];
|
||||
offset: string;
|
||||
update_baseline: string;
|
||||
update_num: number;
|
||||
}
|
||||
// https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space
|
||||
export interface BilibiliWebDynamicResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
ttl: number;
|
||||
data: Data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 作者类型
|
||||
* 更多类型请参考:https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/dynamic/dynamic_enum.md#%E4%BD%9C%E8%80%85%E7%B1%BB%E5%9E%8B
|
||||
*/
|
||||
export type AuthorType = 'AUTHOR_TYPE_PGC' | 'AUTHOR_TYPE_NORMAL' | 'AUTHOR_TYPE_UGC_SEASON' | 'AUTHOR_TYPE_NONE';
|
||||
|
||||
/**
|
||||
* 动态类型
|
||||
* 更多类型请参考:https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/dynamic/dynamic_enum.md#%E5%8A%A8%E6%80%81%E7%B1%BB%E5%9E%8B
|
||||
*/
|
||||
export type DynamicType =
|
||||
| 'DYNAMIC_TYPE_NONE' // 无效动态, 示例: 716510857084796964
|
||||
| 'DYNAMIC_TYPE_FORWARD' // 动态转发
|
||||
| 'DYNAMIC_TYPE_AV' // 投稿视频
|
||||
| 'DYNAMIC_TYPE_PGC' // 剧集(番剧、电影、纪录片)
|
||||
| 'DYNAMIC_TYPE_COURSES' // 课程
|
||||
| 'DYNAMIC_TYPE_WORD' // 纯文字动态, 示例: 718377531474968613
|
||||
| 'DYNAMIC_TYPE_DRAW' // 带图动态, 示例: 718384798557536290
|
||||
| 'DYNAMIC_TYPE_ARTICLE' // 投稿专栏, 示例: 718372214316990512
|
||||
| 'DYNAMIC_TYPE_MUSIC' // 音乐
|
||||
| 'DYNAMIC_TYPE_COMMON_SQUARE' // 装扮, 剧集点评, 普通分享, 示例: 551309621391003098, 716503778995470375, 716481612656672789
|
||||
| 'DYNAMIC_TYPE_COMMON_VERTICAL' // 垂直动态
|
||||
| 'DYNAMIC_TYPE_LIVE' // 直播间分享, 示例: 216042859353895488
|
||||
| 'DYNAMIC_TYPE_MEDIALIST' // 收藏夹, 示例: 534428265320147158
|
||||
| 'DYNAMIC_TYPE_COURSES_SEASON' // 课程, 示例: 717906712866062340
|
||||
| 'DYNAMIC_TYPE_COURSES_BATCH' // 课程批次
|
||||
| 'DYNAMIC_TYPE_AD' // 广告
|
||||
| 'DYNAMIC_TYPE_APPLET' // 小程序
|
||||
| 'DYNAMIC_TYPE_SUBSCRIPTION' // 订阅
|
||||
| 'DYNAMIC_TYPE_LIVE_RCMD' // 直播开播, 示例: 718371505648435205
|
||||
| 'DYNAMIC_TYPE_BANNER' // 横幅
|
||||
| 'DYNAMIC_TYPE_UGC_SEASON' // 合集更新, 示例: 718390979031203873
|
||||
| 'DYNAMIC_TYPE_SUBSCRIPTION_NEW'; // 新订阅
|
||||
/**
|
||||
* 动态主体类型
|
||||
* 更多类型请参考:https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/dynamic/dynamic_enum.md#%E5%8A%A8%E6%80%81%E4%B8%BB%E4%BD%93%E7%B1%BB%E5%9E%8B
|
||||
*/
|
||||
export type MajorType =
|
||||
| 'MAJOR_TYPE_NONE' // 动态失效, 示例: 716510857084796964
|
||||
| 'MAJOR_TYPE_NONE' // 转发动态, 示例: 866756840240709701
|
||||
| 'MAJOR_TYPE_OPUS' // 图文动态, 示例: 870176712256651305
|
||||
| 'MAJOR_TYPE_ARCHIVE' // 视频, 示例: 716526237365829703
|
||||
| 'MAJOR_TYPE_PGC' // 剧集更新, 示例: 645981661420322824
|
||||
| 'MAJOR_TYPE_COURSES' // 课程
|
||||
| 'MAJOR_TYPE_DRAW' // 带图动态, 示例: 716358050743582725
|
||||
| 'MAJOR_TYPE_ARTICLE' // 文章
|
||||
| 'MAJOR_TYPE_MUSIC' // 音频更新
|
||||
| 'MAJOR_TYPE_COMMON' // 一般类型, 示例: 716481612656672789
|
||||
| 'MAJOR_TYPE_LIVE' // 直播间分享, 示例: 267505569812738175
|
||||
| 'MAJOR_TYPE_MEDIALIST' // 收藏夹
|
||||
| 'MAJOR_TYPE_APPLET' // 小程序
|
||||
| 'MAJOR_TYPE_SUBSCRIPTION' // 订阅
|
||||
| 'MAJOR_TYPE_LIVE_RCMD' // 直播状态
|
||||
| 'MAJOR_TYPE_UGC_SEASON' // 合计更新, 示例: 716509100448415814
|
||||
| 'MAJOR_TYPE_SUBSCRIPTION_NEW'; // 新订阅
|
||||
+239
-179
@@ -6,67 +6,7 @@ import utils from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { fallback, queryToBoolean } from '@/utils/readable-social';
|
||||
import cacheIn from './cache';
|
||||
|
||||
/**
|
||||
@by CaoMeiYouRen 2020-05-05 添加注释
|
||||
注意1:以下均以card为根对象
|
||||
注意2:直接动态没有origin,转发动态有origin
|
||||
注意3:转发动态格式统一为:
|
||||
- user.uname: 用户名
|
||||
- item.content: 正文
|
||||
- item.tips: 原动态结果(例如:源动态已被作者删除、图文资源已失效)
|
||||
- origin: 与原动态一致
|
||||
注意4:本总结并不保证完善,而且未来B站可能会修改接口,因此仅供参考
|
||||
|
||||
B站的动态种类繁多,大致可以总结为以下几种:
|
||||
- 文字动态
|
||||
- user.uname: 用户名
|
||||
- item.content: 正文
|
||||
- 图文动态
|
||||
- user.name: 用户名
|
||||
- item.title: 标题
|
||||
- item.description: 简介
|
||||
- item.pictures: { img_src: String }[] 图片数组,图片地址在每项的 img_src 中
|
||||
- 视频动态
|
||||
- aid: av号(以card为根对象没有bv号)
|
||||
- owner.name :用户名
|
||||
- pic: 封面
|
||||
- title: 视频标题
|
||||
- desc: 视频简介
|
||||
- 专栏动态
|
||||
- author.name: 用户名
|
||||
- image_urls: String[] 封面数组
|
||||
- id: cv号
|
||||
- title: 标题
|
||||
- summary: 简介
|
||||
- 音频动态
|
||||
- id: auId 音频id
|
||||
- upper: 上传的用户名称
|
||||
- title: 音频标题
|
||||
- author: 音频作者
|
||||
- cover: 音频封面
|
||||
- 投票动态
|
||||
- user.uname: 用户名
|
||||
- item.content: 正文
|
||||
- 活动专题页
|
||||
- user.uname 用户名
|
||||
- vest.content 正文
|
||||
- sketch.title 活动标题
|
||||
- sketch.desc_text 活动简介
|
||||
- sketch.cover_url 活动封面
|
||||
- sketch.target_url 活动地址
|
||||
- 番剧/电视剧/电影等专题页
|
||||
- cover 单集封面
|
||||
- index_title 单集标题
|
||||
- url 视频地址
|
||||
- apiSeasonInfo.title 番剧名称
|
||||
- apiSeasonInfo.cover 番剧封面
|
||||
- 直播间动态
|
||||
- roomid 直播间id
|
||||
- uname 用户名
|
||||
- title 直播间标题
|
||||
- cover 直播间封面
|
||||
*/
|
||||
import { BilibiliWebDynamicResponse, Item2, Modules } from './api-interface';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/dynamic/:uid/:routeParams?',
|
||||
@@ -74,9 +14,19 @@ export const route: Route = {
|
||||
example: '/bilibili/user/dynamic/2267573',
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', routeParams: '额外参数;请参阅以下说明和表格' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'BILIBILI_COOKIE_*',
|
||||
optional: true,
|
||||
description: `BILIBILI_COOKIE_{uid}: 用于用户关注动态系列路由,对应 uid 的 b 站用户登录后的 Cookie 值,\`{uid}\` 替换为 uid,如 \`BILIBILI_COOKIE_2267573\`,获取方式:
|
||||
1. 打开 [https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=0&type=8](https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=0&type=8)
|
||||
2. 打开控制台,切换到 Network 面板,刷新
|
||||
3. 点击 dynamic_new 请求,找到 Cookie
|
||||
4. 视频和专栏,UP 主粉丝及关注只要求 \`SESSDATA\` 字段,动态需复制整段 Cookie`,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
@@ -106,6 +56,154 @@ export const route: Route = {
|
||||
:::`,
|
||||
};
|
||||
|
||||
const getTitle = (data: Modules) => {
|
||||
const major = data.module_dynamic?.major;
|
||||
if (!major) {
|
||||
return '';
|
||||
}
|
||||
if (major.type === 'MAJOR_TYPE_NONE') {
|
||||
return major.none?.tips;
|
||||
}
|
||||
if (major.type === 'MAJOR_TYPE_COURSES') {
|
||||
return `${major.courses?.title} - ${major.courses?.sub_title}`;
|
||||
}
|
||||
const type = major.type.replace('MAJOR_TYPE_', '').toLowerCase();
|
||||
return major[type]?.title;
|
||||
};
|
||||
const getDes = (data: Modules) => {
|
||||
let desc = '';
|
||||
if (data.module_dynamic?.desc?.text) {
|
||||
desc += data.module_dynamic.desc.text;
|
||||
}
|
||||
const major = data.module_dynamic?.major;
|
||||
// 普通转发
|
||||
if (!major) {
|
||||
return desc;
|
||||
}
|
||||
// 普通分享
|
||||
if (major?.common?.desc) {
|
||||
desc += desc ? `<br>//转发自: ${major.common.desc}` : major.common.desc;
|
||||
return desc;
|
||||
}
|
||||
// 直播动态
|
||||
if (major?.live) {
|
||||
return `${major.live?.desc_first}<br>${major.live?.desc_second}`;
|
||||
}
|
||||
// 图文动态
|
||||
if (major?.opus) {
|
||||
return major?.opus?.summary?.text;
|
||||
}
|
||||
const type = major.type.replace('MAJOR_TYPE_', '').toLowerCase();
|
||||
return major[type]?.desc;
|
||||
};
|
||||
|
||||
const getOriginTitle = (data?: Modules) => data && getTitle(data);
|
||||
const getOriginDes = (data?: Modules) => data && getDes(data);
|
||||
const getOriginName = (data?: Modules) => data?.module_author?.name;
|
||||
const getIframe = (data?: Modules, disableEmbed: boolean = false) => {
|
||||
if (disableEmbed) {
|
||||
return '';
|
||||
}
|
||||
const aid = data?.module_dynamic?.major?.archive?.aid;
|
||||
const bvid = data?.module_dynamic?.major?.archive?.bvid;
|
||||
if (!aid) {
|
||||
return '';
|
||||
}
|
||||
return `<br>${utils.iframe(aid, null, bvid)}<br>`;
|
||||
};
|
||||
|
||||
const getImgs = (data: Modules) => {
|
||||
const imgUrls: string[] = [];
|
||||
const major = data.module_dynamic?.major;
|
||||
if (!major) {
|
||||
return '';
|
||||
}
|
||||
// 动态图片
|
||||
if (major.opus?.pics?.length) {
|
||||
imgUrls.push(...major.opus.pics.map((e) => e.url));
|
||||
}
|
||||
// 专栏封面
|
||||
if (major.article?.covers?.length) {
|
||||
imgUrls.push(...major.article.covers);
|
||||
}
|
||||
// 相簿
|
||||
if (major.draw?.items?.length) {
|
||||
imgUrls.push(...major.draw.items.map((e) => e.src));
|
||||
}
|
||||
const type = major.type.replace('MAJOR_TYPE_', '').toLowerCase();
|
||||
if (major[type]?.cover) {
|
||||
imgUrls.push(major[type].cover);
|
||||
}
|
||||
return imgUrls.map((url) => `<img src="${url}">`);
|
||||
};
|
||||
|
||||
const getUrl = (item?: Item2, useAvid = false) => {
|
||||
const data = item?.modules;
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
let url = '';
|
||||
let text = '';
|
||||
const major = data.module_dynamic?.major;
|
||||
if (!major) {
|
||||
return null;
|
||||
}
|
||||
switch (major?.type) {
|
||||
case 'MAJOR_TYPE_UGC_SEASON':
|
||||
url = major?.ugc_season?.jump_url || '';
|
||||
text = `<br>合集地址:<a href=${url}>${url}</a>`;
|
||||
break;
|
||||
case 'MAJOR_TYPE_ARTICLE':
|
||||
url = `https://www.bilibili.com/read/cv${major?.article?.id}`;
|
||||
text = `<br>专栏地址:<a href=${url}>${url}</a>`;
|
||||
break;
|
||||
case 'MAJOR_TYPE_ARCHIVE': {
|
||||
const archive = major?.archive;
|
||||
const id = useAvid ? `av${archive?.aid}` : archive?.bvid;
|
||||
url = `https://www.bilibili.com/video/${id}`;
|
||||
text = `<br>视频地址:<a href=${url}>${url}</a>`;
|
||||
break;
|
||||
}
|
||||
case 'MAJOR_TYPE_COMMON':
|
||||
url = major?.common?.jump_url || '';
|
||||
text = `<br>地址:<a href=${url}>${url}</a>`;
|
||||
break;
|
||||
case 'MAJOR_TYPE_OPUS':
|
||||
if (item?.type === 'DYNAMIC_TYPE_ARTICLE') {
|
||||
url = `https:${major?.opus?.jump_url}`;
|
||||
text = `<br>专栏地址:<a href=${url}>${url}</a>`;
|
||||
} else if (item?.type === 'DYNAMIC_TYPE_DRAW') {
|
||||
url = `https:${major?.opus?.jump_url}`;
|
||||
text = `<br>图文地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
break;
|
||||
case 'MAJOR_TYPE_PGC': {
|
||||
const pgc = major?.pgc;
|
||||
url = `https://www.bilibili.com/bangumi/play/ep${pgc?.epid}&season_id=${pgc?.season_id}`;
|
||||
text = `<br>剧集地址:<a href=${url}>${url}</a>`;
|
||||
break;
|
||||
}
|
||||
case 'MAJOR_TYPE_COURSES':
|
||||
url = `https://www.bilibili.com/cheese/play/ss${major?.courses?.id}`;
|
||||
text = `<br>课程地址:<a href=${url}>${url}</a>`;
|
||||
break;
|
||||
case 'MAJOR_TYPE_MUSIC':
|
||||
url = `https://www.bilibili.com/audio/au${major?.music?.id}`;
|
||||
text = `<br>音频地址:<a href=${url}>${url}</a>`;
|
||||
break;
|
||||
case 'MAJOR_TYPE_LIVE':
|
||||
url = `https://live.bilibili.com/${major?.live?.id}`;
|
||||
text = `<br>直播间地址:<a href=${url}>${url}</a>`;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
url,
|
||||
text,
|
||||
};
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const uid = ctx.req.param('uid');
|
||||
const routeParams = Object.fromEntries(new URLSearchParams(ctx.req.param('routeParams')));
|
||||
@@ -115,65 +213,39 @@ async function handler(ctx) {
|
||||
const useAvid = fallback(undefined, queryToBoolean(routeParams.useAvid), false);
|
||||
const directLink = fallback(undefined, queryToBoolean(routeParams.directLink), false);
|
||||
|
||||
const cookie = cacheIn.getCookie();
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.vc.bilibili.com/dynamic_svr/v2/dynamic_svr/space_history?host_uid=${uid}`,
|
||||
url: `https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space`,
|
||||
searchParams: {
|
||||
host_mid: uid,
|
||||
platform: 'web',
|
||||
features: 'itemOpusStyle,listOnlyfans,opusBigCover,onlyfansVote',
|
||||
},
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/`,
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
const cards = JSONbig.parse(response.body).data.cards;
|
||||
const body = JSONbig.parse(response.body);
|
||||
if (body?.code === -352) {
|
||||
throw new Error('风控校验失败!请手动配置 Cookie 后重试');
|
||||
}
|
||||
const items = (body as BilibiliWebDynamicResponse)?.data?.items;
|
||||
|
||||
const usernameAndFace = await cacheIn.getUsernameAndFaceFromUID(uid);
|
||||
const author = usernameAndFace[0] ?? cards[0]?.desc?.user_profile?.info.uname;
|
||||
const face = usernameAndFace[1] ?? cards[0]?.desc?.user_profile?.info?.face;
|
||||
const author = usernameAndFace[0] ?? items[0]?.modules?.module_author?.name;
|
||||
const face = usernameAndFace[1] ?? items[0]?.modules?.module_author?.face;
|
||||
cache.set(`bili-username-from-uid-${uid}`, author);
|
||||
cache.set(`bili-userface-from-uid-${uid}`, face);
|
||||
|
||||
const getTitle = (data) => (data ? data.title || data.description || data.content || (data.vest && data.vest.content) || '' : '');
|
||||
const getDes = (data) =>
|
||||
data.dynamic || data.desc || data.description || data.content || data.summary || (data.vest && data.vest.content) + (data.sketch && `<br>${data.sketch.title}<br>${data.sketch.desc_text}`) || data.intro || '';
|
||||
const getOriginDes = (data) => (data && (data.apiSeasonInfo && data.apiSeasonInfo.title && `//转发自: ${data.apiSeasonInfo.title}`) + (data.index_title && `<br>${data.index_title}`)) || '';
|
||||
const getOriginName = (data) => data.uname || (data.author && data.author.name) || (data.upper && data.upper.name) || (data.user && (data.user.uname || data.user.name)) || (data.owner && data.owner.name) || '';
|
||||
const getOriginTitle = (data) => (data.title ? `${data.title}<br>` : '');
|
||||
const getIframe = (data) => (!disableEmbed && data && data.aid ? `<br><br>${utils.iframe(data.aid)}<br>` : '');
|
||||
const getImgs = (data) => {
|
||||
let imgs = '';
|
||||
// 动态图片
|
||||
if (data.pictures) {
|
||||
for (let i = 0; i < data.pictures.length; i++) {
|
||||
imgs += `<img src="${data.pictures[i].img_src}">`;
|
||||
}
|
||||
}
|
||||
// 专栏封面
|
||||
if (data.image_urls) {
|
||||
for (let i = 0; i < data.image_urls.length; i++) {
|
||||
imgs += `<img src="${data.image_urls[i]}">`;
|
||||
}
|
||||
}
|
||||
// 视频封面
|
||||
if (data.pic) {
|
||||
imgs += `<img src="${data.pic}">`;
|
||||
}
|
||||
// 音频/番剧/直播间封面/小视频封面
|
||||
if (data.cover && data.cover.unclipped) {
|
||||
imgs += `<img src="${data.cover.unclipped}">`;
|
||||
} else if (data.cover) {
|
||||
imgs += `<img src="${data.cover}">`;
|
||||
}
|
||||
// 专题页封面
|
||||
if (data.sketch && data.sketch.cover_url) {
|
||||
imgs += `<img src="${data.sketch.cover_url}">`;
|
||||
}
|
||||
return imgs;
|
||||
};
|
||||
const rssItems = await Promise.all(
|
||||
items.map(async (item) => {
|
||||
// const parsed = JSONbig.parse(item.card);
|
||||
|
||||
const items = await Promise.all(
|
||||
cards.map(async (item) => {
|
||||
const parsed = JSONbig.parse(item.card);
|
||||
|
||||
const data = getTitle(parsed.item) ? parsed.item : parsed;
|
||||
const origin = parsed.origin ? JSONbig.parse(parsed.origin) : null;
|
||||
const data = item.modules;
|
||||
const origin = item?.orig?.modules;
|
||||
|
||||
// img
|
||||
let imgHTML = '';
|
||||
@@ -181,93 +253,81 @@ async function handler(ctx) {
|
||||
imgHTML += getImgs(data);
|
||||
|
||||
if (origin) {
|
||||
imgHTML += getImgs(origin.item || origin);
|
||||
}
|
||||
// video小视频
|
||||
let videoHTML = '';
|
||||
if (data.video_playurl) {
|
||||
videoHTML += `<video width="${data.width}" height="${data.height}" controls><source src="${unescape(data.video_playurl).replace(/^http:/, 'https:')}"><source src="${unescape(data.video_playurl)}"></video>`;
|
||||
imgHTML += getImgs(origin);
|
||||
}
|
||||
|
||||
// some rss readers disallow http content.
|
||||
// 部分 RSS 阅读器要求内容必须使用https传输
|
||||
// bilibili short video does support https request, but https request may timeout ocassionally.
|
||||
// to maximize content availability, here add two source tags.
|
||||
// bilibili的API中返回的视频地址采用http,然而经验证,短视频地址支持https访问,但偶尔会返回超时错误(可能是网络原因)。
|
||||
// 因此保险起见加入两个source标签
|
||||
|
||||
// link
|
||||
let link = '';
|
||||
if (data.dynamic_id) {
|
||||
link = `https://t.bilibili.com/${data.dynamic_id}`;
|
||||
} else if (item.desc?.dynamic_id) {
|
||||
link = `https://t.bilibili.com/${item.desc.dynamic_id}`;
|
||||
if (item.id_str) {
|
||||
link = `https://t.bilibili.com/${item.id_str}`;
|
||||
}
|
||||
|
||||
// emoji
|
||||
let data_content = getDes(data);
|
||||
let description = getDes(data) || '';
|
||||
// 换行处理
|
||||
data_content = data_content.replaceAll('\r\n', '<br>').replaceAll('\n', '<br>');
|
||||
if (item.display.emoji_info && showEmoji) {
|
||||
const emoji = item.display.emoji_info.emoji_details;
|
||||
for (const item of emoji) {
|
||||
data_content = data_content.replaceAll(
|
||||
new RegExp(`\\${item.text}`.replaceAll(/\\?/g, '\\?'), 'g'),
|
||||
`<img alt="${item.text}" src="${item.url}"style="margin: -1px 1px 0px; display: inline-block; width: 20px; height: 20px; vertical-align: text-bottom;" title="" referrerpolicy="no-referrer">`
|
||||
);
|
||||
description = description.replaceAll('\r\n', '<br>').replaceAll('\n', '<br>');
|
||||
if (data.module_dynamic?.desc?.rich_text_nodes?.length && showEmoji) {
|
||||
const nodes = data.module_dynamic?.desc?.rich_text_nodes;
|
||||
for (const node of nodes) {
|
||||
if (node?.emoji) {
|
||||
const emoji = node.emoji;
|
||||
description = description.replaceAll(
|
||||
emoji.text,
|
||||
`<img alt="${emoji.text}" src="${emoji.icon_url}"style="margin: -1px 1px 0px; display: inline-block; width: 20px; height: 20px; vertical-align: text-bottom;" title="" referrerpolicy="no-referrer">`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
const getUrl = (data) => {
|
||||
if (!data) {
|
||||
return '';
|
||||
}
|
||||
let url;
|
||||
if (data.aid) {
|
||||
const id = useAvid ? `av${data.aid}` : item?.desc?.bvid || item?.desc?.origin?.bvid;
|
||||
url = `https://www.bilibili.com/video/${id}`;
|
||||
directLink && (link = url);
|
||||
return `<br>视频地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.image_urls) {
|
||||
url = `https://www.bilibili.com/read/cv${data.id}`;
|
||||
directLink && (link = url);
|
||||
return `<br>专栏地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.upper) {
|
||||
url = `https://www.bilibili.com/audio/au${data.id}`;
|
||||
directLink && (link = url);
|
||||
return `<br>音频地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.roomid) {
|
||||
url = `https://live.bilibili.com/${data.roomid}`;
|
||||
directLink && (link = url);
|
||||
return `<br>直播间地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.sketch) {
|
||||
url = data.sketch.target_url;
|
||||
directLink && (link = url);
|
||||
return `<br>活动地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.url) {
|
||||
url = data.url;
|
||||
directLink && (link = url);
|
||||
return `<br>地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
if (data.image_urls && displayArticle) {
|
||||
data_content = (await cacheIn.getArticleDataFromCvid(data.id, uid)).description;
|
||||
if (item.type === 'DYNAMIC_TYPE_ARTICLE' && displayArticle) {
|
||||
// 抓取专栏全文
|
||||
const cvid = data.module_dynamic?.major?.opus?.jump_url?.match?.(/cv(\d+)/)?.[0];
|
||||
if (cvid) {
|
||||
description = (await cacheIn.getArticleDataFromCvid(cvid, uid)).description || '';
|
||||
}
|
||||
}
|
||||
|
||||
const urlResult = getUrl(item, useAvid);
|
||||
const originUrlResult = getUrl(item?.orig, useAvid);
|
||||
let urlText = '';
|
||||
if (urlResult) {
|
||||
urlText += urlResult.text;
|
||||
if (directLink) {
|
||||
link = urlResult.url;
|
||||
}
|
||||
}
|
||||
if (originUrlResult) {
|
||||
urlText += originUrlResult.text;
|
||||
if (directLink) {
|
||||
link = originUrlResult.url;
|
||||
}
|
||||
}
|
||||
|
||||
let originDescription = '';
|
||||
const originName = getOriginName(origin);
|
||||
const originTitle = getOriginTitle(origin);
|
||||
const originDes = getOriginDes(origin);
|
||||
if (originName) {
|
||||
originDescription += `<br>//转发自: @${getOriginName(origin)}: `;
|
||||
}
|
||||
if (originTitle) {
|
||||
originDescription += originTitle;
|
||||
}
|
||||
if (originDes) {
|
||||
originDescription += `<br>${originDes}`;
|
||||
}
|
||||
const imgHTMLSource = imgHTML ? `<br>${imgHTML}` : '';
|
||||
return {
|
||||
title: getTitle(data),
|
||||
description: (() => {
|
||||
const description = data_content || getDes(data);
|
||||
const originName = origin && getOriginName(origin) ? `<br><br>//转发自: @${getOriginName(origin)}: ${getOriginTitle(origin.item || origin)}${getDes(origin.item || origin)}` : getOriginDes(origin);
|
||||
const imgHTMLSource = imgHTML ? `<br>${imgHTML}` : '';
|
||||
const videoHTMLSource = videoHTML ? `<br>${videoHTML}` : '';
|
||||
return `${description}${originName}<br>${getUrl(data)}${getUrl(origin)}${getIframe(data)}${getIframe(origin)}${imgHTMLSource}${videoHTMLSource}`;
|
||||
})(),
|
||||
pubDate: item.desc?.timestamp ? parseDate(item.desc.timestamp, 'X') : null,
|
||||
title: getTitle(data) || '',
|
||||
description: `${description}${originDescription}<br>${urlText}${getIframe(data, disableEmbed)}${getIframe(origin, disableEmbed)}${imgHTMLSource}`,
|
||||
pubDate: data.module_author?.pub_ts ? parseDate(data.module_author.pub_ts, 'X') : undefined,
|
||||
link,
|
||||
author,
|
||||
};
|
||||
@@ -279,6 +339,6 @@ async function handler(ctx) {
|
||||
link: `https://space.bilibili.com/${uid}/dynamic`,
|
||||
description: `${author} 的 bilibili 动态`,
|
||||
image: face,
|
||||
item: items,
|
||||
item: rssItems,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { config } from '@/config';
|
||||
import md5 from '@/utils/md5';
|
||||
import CryptoJS from 'crypto-js';
|
||||
|
||||
function iframe(aid, page, bvid) {
|
||||
function iframe(aid: any, page?: any, bvid?: any) {
|
||||
return `<iframe src="https://www.bilibili.com/blackboard/html5mobileplayer.html?${bvid ? `bvid=${bvid}` : `aid=${aid}`}${
|
||||
page ? `&page=${page}` : ''
|
||||
}&high_quality=1&autoplay=0" width="650" height="477" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe>`;
|
||||
|
||||
Reference in New Issue
Block a user