koishi-plugin-bilibili-notify
Version:
Koishi bilibili notify plugin
811 lines (762 loc) • 85.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-explicit-any */
const koishi_1 = require("koishi");
const path_1 = require("path");
const url_1 = require("url");
// 动态类型
const DYNAMIC_TYPE_NONE = 'DYNAMIC_TYPE_NONE';
const DYNAMIC_TYPE_FORWARD = 'DYNAMIC_TYPE_FORWARD';
const DYNAMIC_TYPE_AV = 'DYNAMIC_TYPE_AV';
const DYNAMIC_TYPE_PGC = 'DYNAMIC_TYPE_PGC';
const DYNAMIC_TYPE_COURSES = 'DYNAMIC_TYPE_COURSES';
const DYNAMIC_TYPE_WORD = 'DYNAMIC_TYPE_WORD';
const DYNAMIC_TYPE_DRAW = 'DYNAMIC_TYPE_DRAW';
const DYNAMIC_TYPE_ARTICLE = 'DYNAMIC_TYPE_ARTICLE';
const DYNAMIC_TYPE_MUSIC = 'DYNAMIC_TYPE_MUSIC';
const DYNAMIC_TYPE_COMMON_SQUARE = 'DYNAMIC_TYPE_COMMON_SQUARE';
const DYNAMIC_TYPE_COMMON_VERTICAL = 'DYNAMIC_TYPE_COMMON_VERTICAL';
const DYNAMIC_TYPE_LIVE = 'DYNAMIC_TYPE_LIVE';
const DYNAMIC_TYPE_MEDIALIST = 'DYNAMIC_TYPE_MEDIALIST';
const DYNAMIC_TYPE_COURSES_SEASON = 'DYNAMIC_TYPE_COURSES_SEASON';
const DYNAMIC_TYPE_COURSES_BATCH = 'DYNAMIC_TYPE_COURSES_BATCH';
const DYNAMIC_TYPE_AD = 'DYNAMIC_TYPE_AD';
const DYNAMIC_TYPE_APPLET = 'DYNAMIC_TYPE_APPLET';
const DYNAMIC_TYPE_SUBSCRIPTION = 'DYNAMIC_TYPE_SUBSCRIPTION';
const DYNAMIC_TYPE_LIVE_RCMD = 'DYNAMIC_TYPE_LIVE_RCMD';
const DYNAMIC_TYPE_BANNER = 'DYNAMIC_TYPE_BANNER';
const DYNAMIC_TYPE_UGC_SEASON = 'DYNAMIC_TYPE_UGC_SEASON';
const DYNAMIC_TYPE_SUBSCRIPTION_NEW = 'DYNAMIC_TYPE_SUBSCRIPTION_NEW';
// 内容卡片类型
/* const ADDITIONAL_TYPE_NONE = 'ADDITIONAL_TYPE_NONE'
const ADDITIONAL_TYPE_PGC = 'ADDITIONAL_TYPE_PGC'
const ADDITIONAL_TYPE_GOODS = 'ADDITIONAL_TYPE_GOODS'
const ADDITIONAL_TYPE_VOTE = 'ADDITIONAL_TYPE_VOTE'
const ADDITIONAL_TYPE_COMMON = 'ADDITIONAL_TYPE_COMMON'
const ADDITIONAL_TYPE_MATCH = 'ADDITIONAL_TYPE_MATCH'
const ADDITIONAL_TYPE_UP_RCMD = 'ADDITIONAL_TYPE_UP_RCMD'
const ADDITIONAL_TYPE_UGC = 'ADDITIONAL_TYPE_UGC' */
const ADDITIONAL_TYPE_RESERVE = 'ADDITIONAL_TYPE_RESERVE';
class GenerateImg extends koishi_1.Service {
static inject = ['puppeteer', 'ba'];
giConfig;
constructor(ctx, config) {
super(ctx, 'gi');
this.giConfig = config;
}
async generateLiveImg(data, username, userface, liveStatus /*0未开播 1刚开播 2已开播 3停止直播*/) {
const [titleStatus, liveTime, cover] = await this.getLiveStatus(data.live_time, liveStatus);
// 加载字体
const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, 'font/HYZhengYuan-75W.ttf'));
// 卡片内容
const html = `
<!DOCTYPE html>
<html>
<head>
<title>直播通知</title>
<style>
@font-face {
font-family: "Custom Font";
src: url(${fontURL});
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "${this.giConfig.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
}
html {
width: 800px;
height: auto;
}
.background {
width: 100%;
height: auto;
padding: 15px;
background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
overflow: hidden;
}
.base-plate {
width: 100%;
height: auto;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 15px;
border-radius: 10px;
background-color: #FFF5EE;
}
.card {
width: 100%;
height: auto;
border-radius: 5px;
padding: 15px;
overflow: hidden;
background-color: #fff;
}
.card img {
border-radius: 5px 5px 0 0;
max-width: 100%;
/* 设置最大宽度为容器宽度的100% */
max-height: 80%;
/* 设置最大高度为容器高度的90% */
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 5px;
margin-bottom: 10px;
}
.card-title {
line-height: 50px;
}
.card-body {
padding: 2px 16px;
margin-bottom: 10px;
}
.live-broadcast-info {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.anchor-avatar {
width: 50px;
/* 主播头像大小 */
height: auto;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.broadcast-message {
display: inline-block;
margin-left: 10px;
font-size: 20px;
color: #333;
}
.card-text {
color: grey;
font-size: 20px;
}
.card-link {
display: flex;
justify-content: space-between;
text-decoration: none;
font-size: 20px;
margin-top: 10px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="background">
<div ${this.giConfig.removeBorder ? '' : 'class="base-plate"'}>
<div class="card">
<img src="${cover ? data.user_cover : data.keyframe}"
alt="封面">
<div class="card-body">
<div class="card-header">
<h1 class="card-title">${data.title}</h1>
<div class="live-broadcast-info">
<!-- 主播头像 -->
<img style="border-radius: 10px; margin-left: 10px" class="anchor-avatar"
src="${userface}" alt="主播头像">
<span class="broadcast-message">${username}${titleStatus}</span>
</div>
</div>
${this.giConfig.hideDesc ? '' : `<p class="card-text">${data.description ? data.description : '这个主播很懒,什么都简介都没写'}</p>`}
<p class="card-link">
${liveStatus !== 3 ? `<span>人气:${data.online > 10000 ? `${(data.online / 10000).toFixed(1)}万` : data.online}</span>` : ''}
<span>分区名称:${data.area_name}</span>
</p>
<p class="card-link">
<span>${liveTime}</span>
</p>
</div>
</div>
</div>
</div>
</body>
</html>
`;
// 多次尝试生成图片
const attempts = 3;
for (let i = 0; i < attempts; i++) {
try {
// 判断渲染方式
if (this.giConfig.renderType) { // 为1则为真,进入page模式
const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
const page = await this.ctx.puppeteer.page();
await page.goto(htmlPath);
await page.setContent(html, { waitUntil: 'networkidle0' });
const elementHandle = await page.$('html');
const boundingBox = await elementHandle.boundingBox();
const buffer = await page.screenshot({
type: 'png',
clip: {
x: boundingBox.x,
y: boundingBox.y,
width: boundingBox.width,
height: boundingBox.height
}
});
await elementHandle.dispose();
await page.close();
return { buffer };
}
// 使用render模式渲染
const pic = await this.ctx.puppeteer.render(html);
return { pic };
}
catch (e) {
if (i === attempts - 1) { // 已尝试三次
throw new Error('生成图片失败!错误: ' + e.toString());
}
}
}
}
async generateDynamicImg(data) {
// module_author
const module_author = data.modules.module_author;
const avatarUrl = module_author.face;
const upName = module_author.name;
let pubTime = this.unixTimestampToString(module_author.pub_ts);
// dynamicCard
let dynamicCardUrl;
let dynamicCardId;
let dynamicCardColor;
if (module_author.decorate) {
dynamicCardUrl = module_author.decorate.card_url;
dynamicCardId = module_author.decorate.fan.num_str;
dynamicCardColor = module_author.decorate.fan.color;
}
// module_stat
const module_stat = data.modules.module_stat;
const comment = module_stat.comment.count;
const forward = module_stat.forward.count;
const like = module_stat.like.count;
// TOPIC
const topic = data.modules.module_dynamic.topic ? data.modules.module_dynamic.topic.name : '';
const getDynamicMajor = async (dynamicMajorData, forward) => {
// 定义返回值
let main = '';
let link = '';
// 定义forward类型返回值
let forwardInfo;
// 最基本的图文处理
const basicDynamic = () => {
const module_dynamic = dynamicMajorData.modules.module_dynamic;
if (module_dynamic.desc) {
const richText = module_dynamic.desc.rich_text_nodes.reduce((accumulator, currentValue) => {
if (currentValue.emoji) {
return accumulator + `<img style="width:28px; height:28px;" src="${currentValue.emoji.icon_url}"/>`;
}
else {
return accumulator + currentValue.text;
}
}, '');
// 关键字和正则屏蔽
if (this.giConfig.filter.enable) { // 开启动态屏蔽功能
if (this.giConfig.filter.regex) { // 正则屏蔽
const reg = new RegExp(this.giConfig.filter.regex);
if (reg.test(richText))
throw new Error('出现关键词,屏蔽该动态');
}
if (this.giConfig.filter.keywords.length !== 0 &&
this.giConfig.filter.keywords
.some(keyword => richText.includes(keyword))) {
throw new Error('出现关键词,屏蔽该动态');
}
}
// 查找\n
const text = richText.replace(/\n/g, '<br>');
// 拼接字符串
if (text) {
main += `
<div class="card-details">
${text}
</div>
`;
}
}
// 图片
let major = '';
const arrowImg = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, 'img/arrow.png'));
if (module_dynamic.major && module_dynamic.major.draw) {
if (module_dynamic.major.draw.items.length === 1) {
const height = module_dynamic.major.draw.items[0].height;
console.log(height);
if (height > 3000) {
major += `
<div class="single-photo-container">
<img class="single-photo-item" src="${module_dynamic.major.draw.items[0].src}"/>
<div class="single-photo-mask">
<span class="single-photo-mask-text">点击链接浏览全部</span>
</div>
<img class="single-photo-mask-arrow" src="${arrowImg}"/>
</div>
`;
}
else {
major += `
<div class="single-photo-container">
<img class="single-photo-item" src="${module_dynamic.major.draw.items[0].src}"/>
</div>
`;
}
}
else if (module_dynamic.major.draw.items.length === 4) {
major += module_dynamic.major.draw.items.reduce((acc, cV) => {
return acc + `<img class="four-photo-item" src="${cV.src}"/>`;
}, '');
}
else {
major += module_dynamic.major.draw.items.reduce((acc, cV) => {
return acc + `<img class="photo-item" src="${cV.src}"/>`;
}, '');
}
main += `
<div class="card-major">
${major}
</div>
`;
}
};
// 判断动态类型
switch (dynamicMajorData.type) {
case DYNAMIC_TYPE_WORD:
case DYNAMIC_TYPE_DRAW:
case DYNAMIC_TYPE_FORWARD: {
// DYNAMIC_TYPE_DRAW 带图动态 DYNAMIC_TYPE_WORD 文字动态 DYNAMIC_TYPE_FORWARD 转发动态
basicDynamic();
// 转发动态
if (dynamicMajorData.type === DYNAMIC_TYPE_FORWARD) {
//转发动态屏蔽
if (this.giConfig.filter.enable && this.giConfig.filter.forward) {
throw new Error('已屏蔽转发动态');
}
// User info
const forward_module_author = dynamicMajorData.orig.modules.module_author;
const forwardUserAvatarUrl = forward_module_author.face;
const forwardUserName = forward_module_author.name;
// 获取转发的动态
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [forwardMain, _, forwardInfo] = await getDynamicMajor(dynamicMajorData.orig, true);
// 拼接main
main += `
<div class="card-forward">
<div class="forward-userinfo">
<img class="forward-avatar" src="${forwardUserAvatarUrl}" alt="avatar">
<span class="forward-username">${forwardUserName} ${forwardInfo ? forwardInfo : ''}</span>
</div>
<div class="forward-main">
${forwardMain}
</div>
</div>
`;
}
// 判断是否有附加信息
if (dynamicMajorData.modules.module_dynamic.additional) {
const additional = dynamicMajorData.modules.module_dynamic.additional;
// 有附加信息,判断类型
switch (additional.type) {
case ADDITIONAL_TYPE_RESERVE: { // 预约信息
const reserve = additional.reserve;
// 定义按钮
let button;
// 判断按钮类型
if (reserve.button.uncheck.text === '已结束') {
button = `
<button class="reserve-button-end">
<span>${reserve.button.uncheck.text}</span>
</button>
`;
}
else {
button = `
<button class="reserve-button-ing">
<svg class="bili-dyn-card-reserve__action__icon" style="width: 16px; height: 16px;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 16 16" width="16" height="16">
<path
d="M3.0000133333333334 6.999199999999999C3.0000133333333334 4.23776 5.2385866666666665 1.9991866666666667 8 1.9991866666666667C10.761433333333333 1.9991866666666667 13 4.23776 13 6.999199999999999L13 9.860933333333332C13 9.923533333333333 13.024899999999999 9.983633333333334 13.069199999999999 10.027933333333333L13.588366666666666 10.5471C14.389533333333333 11.348299999999998 13.914133333333334 12.734533333333333 12.754199999999999 12.8183C11.535999999999998 12.906233333333333 9.818933333333334 12.999199999999998 8 12.999199999999998C6.181073333333334 12.999199999999998 4.464026666666666 12.906233333333333 3.2458266666666664 12.8183C2.0859066666666664 12.734533333333333 1.61046 11.348299999999998 2.4116466666666665 10.547133333333333L2.93084 10.027933333333333C2.975133333333333 9.983633333333334 3.0000133333333334 9.923533333333333 3.0000133333333334 9.860933333333332L3.0000133333333334 6.999199999999999zM8 2.9991866666666667C5.790873333333334 2.9991866666666667 4.000013333333333 4.790046666666666 4.000013333333333 6.999199999999999L4.000013333333333 9.860933333333332C4.000013333333333 10.1888 3.8697733333333333 10.5032 3.6379466666666667 10.735033333333334L3.1187466666666666 11.254233333333334C2.911966666666667 11.461 3.0317600000000002 11.800199999999998 3.317833333333333 11.820899999999998C4.5211266666666665 11.907766666666667 6.212726666666666 11.999199999999998 8 11.999199999999998C9.787266666666666 11.999199999999998 11.4789 11.907733333333333 12.682199999999998 11.820899999999998C12.968233333333332 11.800199999999998 13.088033333333332 11.461 12.881266666666665 11.254233333333334L12.362066666666665 10.735033333333334C12.130233333333333 10.5032 12 10.1888 12 9.860933333333332L12 6.999199999999999C12 4.790046666666666 10.209166666666667 2.9991866666666667 8 2.9991866666666667z"
fill="currentColor"></path>
<path
d="M8.720066666666666 2.0260466666666668C8.720066666666666 2.42372 8.397666666666666 2.746093333333333 8 2.746093333333333C7.602333333333332 2.746093333333333 7.279933333333333 2.42372 7.279933333333333 2.0260466666666668C7.279933333333333 1.6283666666666667 7.602333333333332 1.3059866666666666 8 1.3059866666666666C8.397666666666666 1.3059866666666666 8.720066666666666 1.6283666666666667 8.720066666666666 2.0260466666666668z"
fill="currentColor"></path>
<path
d="M6.791266666666666 12.499199999999998C6.791266666666666 13.173966666666667 7.335266666666667 13.715866666666665 8 13.715866666666665C8.664766666666665 13.715866666666665 9.208733333333333 13.173966666666667 9.208733333333333 12.499199999999998L10.208733333333333 12.499199999999998C10.208733333333333 13.720566666666667 9.2227 14.715866666666665 8 14.715866666666665C6.777346666666666 14.715866666666665 5.791273333333333 13.720566666666667 5.791273333333333 12.499199999999998L6.791266666666666 12.499199999999998z"
fill="currentColor"></path>
</svg>
<span>${reserve.button.uncheck.text}</span>
</button>
`;
}
main += `
<div class="card-reserve">
<div class="reserve-main">
<div class="reserve-title">
${reserve.title}
</div>
<div class="reserve-desc">
<div class="reserve-info">
<span class="reserve-time">${reserve.desc1.text}</span>
<span class="reserve-num">${reserve.desc2.text}</span>
</div>
${reserve.desc3 ?
`<div class="reserve-prize">
<svg class="bili-dyn-card-reserve__lottery__icon"
style="width: 16px; height: 16px;" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 16 16" width="16"
height="16">
<path
d="M2.99998 7.785666666666666C3.2761266666666664 7.785666666666666 3.49998 8.0095 3.49998 8.285666666666666L3.49998 12.285666666666666C3.49998 12.719566666666667 3.8517599999999996 13.071333333333332 4.285693333333333 13.071333333333332L11.714266666666667 13.071333333333332C12.1482 13.071333333333332 12.5 12.719566666666667 12.5 12.285666666666666L12.5 8.285666666666666C12.5 8.0095 12.723833333333333 7.785666666666666 13 7.785666666666666C13.276133333333334 7.785666666666666 13.5 8.0095 13.5 8.285666666666666L13.5 12.285666666666666C13.5 13.271866666666668 12.7005 14.071333333333332 11.714266666666667 14.071333333333332L4.285693333333333 14.071333333333332C3.2994733333333333 14.071333333333332 2.49998 13.271866666666668 2.49998 12.285666666666666L2.49998 8.285666666666666C2.49998 8.0095 2.7238399999999996 7.785666666666666 2.99998 7.785666666666666z"
fill="currentColor"></path>
<path
d="M1.9285533333333333 5.857139999999999C1.9285533333333333 5.107613333333333 2.5361666666666665 4.5 3.285693333333333 4.5L12.714266666666667 4.5C13.463799999999999 4.5 14.071399999999999 5.107613333333333 14.071399999999999 5.857139999999999L14.071399999999999 7.134066666666667C14.071399999999999 7.793799999999999 13.590066666666667 8.373766666666667 12.905000000000001 8.4432C12.058933333333332 8.528966666666665 10.470166666666666 8.642866666666666 8 8.642866666666666C5.529819999999999 8.642866666666666 3.9410399999999997 8.528966666666665 3.09498 8.4432C2.4099066666666666 8.373766666666667 1.9285533333333333 7.793799999999999 1.9285533333333333 7.134066666666667L1.9285533333333333 5.857139999999999zM3.285693333333333 5.5C3.088453333333333 5.5 2.9285533333333333 5.6599 2.9285533333333333 5.857139999999999L2.9285533333333333 7.134066666666667C2.9285533333333333 7.3082 3.0432666666666663 7.432833333333333 3.1958066666666665 7.4483C4.00544 7.530366666666667 5.560420000000001 7.6428666666666665 8 7.6428666666666665C10.439566666666666 7.6428666666666665 11.994533333333333 7.530366666666667 12.804133333333333 7.4483C12.9567 7.432833333333333 13.071399999999999 7.3082 13.071399999999999 7.134066666666667L13.071399999999999 5.857139999999999C13.071399999999999 5.6599 12.911499999999998 5.5 12.714266666666667 5.5L3.285693333333333 5.5z"
fill="currentColor"></path>
<path
d="M4.357126666666666 3.5714733333333335C4.357126666666666 2.506353333333333 5.220573333333333 1.6429066666666667 6.285693333333333 1.6429066666666667C7.350833333333332 1.6429066666666667 8.214266666666667 2.506353333333333 8.214266666666667 3.5714733333333335L8.214266666666667 5.500046666666666L6.285693333333333 5.500046666666666C5.220573333333333 5.500046666666666 4.357126666666666 4.636593333333333 4.357126666666666 3.5714733333333335zM6.285693333333333 2.6429066666666667C5.77286 2.6429066666666667 5.357126666666667 3.0586399999999996 5.357126666666667 3.5714733333333335C5.357126666666667 4.084313333333333 5.77286 4.500046666666666 6.285693333333333 4.500046666666666L7.214266666666667 4.500046666666666L7.214266666666667 3.5714733333333335C7.214266666666667 3.0586399999999996 6.798533333333333 2.6429066666666667 6.285693333333333 2.6429066666666667z"
fill="currentColor"></path>
<path
d="M7.785666666666666 3.5714733333333335C7.785666666666666 2.506353333333333 8.649133333333332 1.6429066666666667 9.714266666666667 1.6429066666666667C10.779399999999999 1.6429066666666667 11.642866666666666 2.506353333333333 11.642866666666666 3.5714733333333335C11.642866666666666 4.636593333333333 10.779399999999999 5.500046666666666 9.714266666666667 5.500046666666666L7.785666666666666 5.500046666666666L7.785666666666666 3.5714733333333335zM9.714266666666667 2.6429066666666667C9.201433333333332 2.6429066666666667 8.785666666666666 3.0586399999999996 8.785666666666666 3.5714733333333335L8.785666666666666 4.500046666666666L9.714266666666667 4.500046666666666C10.2271 4.500046666666666 10.642866666666666 4.084313333333333 10.642866666666666 3.5714733333333335C10.642866666666666 3.0586399999999996 10.2271 2.6429066666666667 9.714266666666667 2.6429066666666667z"
fill="currentColor"></path>
<path
d="M8 3.7856466666666666C8.276133333333332 3.7856466666666666 8.5 4.009499999999999 8.5 4.285646666666667L8.5 13.142800000000001C8.5 13.418933333333332 8.276133333333332 13.642800000000001 8 13.642800000000001C7.723833333333333 13.642800000000001 7.5 13.418933333333332 7.5 13.142800000000001L7.5 4.285646666666667C7.5 4.009499999999999 7.723833333333333 3.7856466666666666 8 3.7856466666666666z"
fill="currentColor"></path>
</svg>
<span>${reserve.desc3.text}</span>
<svg style="width: 12px; height: 12px;" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 12 12" width="12"
height="12">
<path
d="M4.359835 1.609835C4.21339 1.756285 4.21339 1.99372 4.359835 2.140165L8.0429 5.823225C8.140525 5.920875 8.140525 6.079125 8.0429 6.176775L4.359835 9.859825C4.21339 10.006275 4.21339 10.243725 4.359835 10.390175C4.506285 10.5366 4.743725 10.5366 4.89017 10.390175L8.573225 6.7071C8.96375 6.316575 8.96375 5.683425 8.573225 5.2929L4.89017 1.609835C4.743725 1.46339 4.506285 1.46339 4.359835 1.609835z"
fill="currentColor"></path>
</svg>
</div>` : ''}
</div>
</div>
<div class="reserve-button">
${button}
</div>
</div>
`;
}
}
}
link += `请将$替换为. www$bilibili$com/opus/${dynamicMajorData.id_str}`;
break;
}
case DYNAMIC_TYPE_AV: { // 投稿新视频
// 处理文字
basicDynamic();
const archive = dynamicMajorData.modules.module_dynamic.major.archive;
if (archive.badge.text === '投稿视频') {
if (forward) {
forwardInfo = '投稿了视频';
}
else {
pubTime = `${pubTime} · 投稿了视频`;
}
}
main += `
<div class="card-video">
<div class="video-cover">
<img src="${archive.cover}"
alt="">
<div class="cover-mask"></div>
<span>${archive.duration_text}</span>
</div>
<div class="video-info">
<div class="video-info-header">
<div class="video-title">
${archive.title}
</div>
<div class="video-introduction">
${archive.desc}
</div>
</div>
<div class="video-stat">
<div class="video-stat-item">
<svg style="width: 16px; height: 16px;" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 16 16" width="16"
height="16">
<path
d="M8 3.3320333333333334C6.321186666666667 3.3320333333333334 4.855333333333333 3.4174399999999996 3.820593333333333 3.5013466666666666C3.1014733333333333 3.5596599999999996 2.5440733333333334 4.109013333333333 2.48 4.821693333333333C2.4040466666666664 5.666533333333334 2.333333333333333 6.780666666666666 2.333333333333333 7.998666666666666C2.333333333333333 9.216733333333334 2.4040466666666664 10.330866666666665 2.48 11.175699999999999C2.5440733333333334 11.888366666666666 3.1014733333333333 12.437733333333334 3.820593333333333 12.496066666666666C4.855333333333333 12.579933333333333 6.321186666666667 12.665333333333333 8 12.665333333333333C9.678999999999998 12.665333333333333 11.144933333333334 12.579933333333333 12.179733333333333 12.496033333333333C12.898733333333332 12.4377 13.456 11.888533333333331 13.520066666666667 11.176033333333333C13.595999999999998 10.331533333333333 13.666666666666666 9.217633333333332 13.666666666666666 7.998666666666666C13.666666666666666 6.779766666666667 13.595999999999998 5.665846666666667 13.520066666666667 4.821366666666666C13.456 4.108866666666666 12.898733333333332 3.55968 12.179733333333333 3.5013666666666663C11.144933333333334 3.417453333333333 9.678999999999998 3.3320333333333334 8 3.3320333333333334zM3.7397666666666667 2.50462C4.794879999999999 2.41906 6.288386666666666 2.3320333333333334 8 2.3320333333333334C9.7118 2.3320333333333334 11.2054 2.4190733333333334 12.260533333333331 2.5046399999999998C13.458733333333331 2.6018133333333333 14.407866666666665 3.5285199999999994 14.516066666666667 4.73182C14.593933333333332 5.597933333333334 14.666666666666666 6.7427 14.666666666666666 7.998666666666666C14.666666666666666 9.2547 14.593933333333332 10.399466666666665 14.516066666666667 11.2656C14.407866666666665 12.468866666666665 13.458733333333331 13.395566666666667 12.260533333333331 13.492766666666665C11.2054 13.578333333333333 9.7118 13.665333333333333 8 13.665333333333333C6.288386666666666 13.665333333333333 4.794879999999999 13.578333333333333 3.7397666666666667 13.492799999999999C2.541373333333333 13.395599999999998 1.5922066666666668 12.468633333333333 1.4840200000000001 11.265266666666665C1.4061199999999998 10.3988 1.3333333333333333 9.253866666666667 1.3333333333333333 7.998666666666666C1.3333333333333333 6.743533333333333 1.4061199999999998 5.598579999999999 1.4840200000000001 4.732153333333333C1.5922066666666668 3.5287466666666667 2.541373333333333 2.601793333333333 3.7397666666666667 2.50462z"
fill="currentColor"></path>
<path
d="M9.8092 7.3125C10.338433333333333 7.618066666666666 10.338433333333333 8.382 9.809166666666666 8.687533333333333L7.690799999999999 9.910599999999999C7.161566666666666 10.216133333333332 6.5 9.8342 6.500006666666666 9.223066666666666L6.500006666666666 6.776999999999999C6.500006666666666 6.165873333333334 7.161566666666666 5.783913333333333 7.690799999999999 6.089479999999999L9.8092 7.3125z"
fill="currentColor"></path>
</svg>
<span>${archive.stat.play}</span>
</div>
<div class="video-stat-item">
<svg style="width: 16px; height: 16px;" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 16 16" width="16"
height="16">
<path
d="M8 3.3320333333333334C6.321186666666667 3.3320333333333334 4.855333333333333 3.4174399999999996 3.820593333333333 3.5013466666666666C3.1014733333333333 3.5596599999999996 2.5440733333333334 4.109013333333333 2.48 4.821693333333333C2.4040466666666664 5.666533333333334 2.333333333333333 6.780666666666666 2.333333333333333 7.998666666666666C2.333333333333333 9.216733333333334 2.4040466666666664 10.330866666666665 2.48 11.175699999999999C2.5440733333333334 11.888366666666666 3.1014733333333333 12.437733333333334 3.820593333333333 12.496066666666666C4.855333333333333 12.579933333333333 6.321186666666667 12.665333333333333 8 12.665333333333333C9.678999999999998 12.665333333333333 11.144933333333334 12.579933333333333 12.179733333333333 12.496033333333333C12.898733333333332 12.4377 13.456 11.888533333333331 13.520066666666667 11.176033333333333C13.595999999999998 10.331533333333333 13.666666666666666 9.217633333333332 13.666666666666666 7.998666666666666C13.666666666666666 6.779766666666667 13.595999999999998 5.665846666666667 13.520066666666667 4.821366666666666C13.456 4.108866666666666 12.898733333333332 3.55968 12.179733333333333 3.5013666666666663C11.144933333333334 3.417453333333333 9.678999999999998 3.3320333333333334 8 3.3320333333333334zM3.7397666666666667 2.50462C4.794879999999999 2.41906 6.288386666666666 2.3320333333333334 8 2.3320333333333334C9.7118 2.3320333333333334 11.2054 2.4190733333333334 12.260533333333331 2.5046399999999998C13.458733333333331 2.6018133333333333 14.407866666666665 3.5285199999999994 14.516066666666667 4.73182C14.593933333333332 5.597933333333334 14.666666666666666 6.7427 14.666666666666666 7.998666666666666C14.666666666666666 9.2547 14.593933333333332 10.399466666666665 14.516066666666667 11.2656C14.407866666666665 12.468866666666665 13.458733333333331 13.395566666666667 12.260533333333331 13.492766666666665C11.2054 13.578333333333333 9.7118 13.665333333333333 8 13.665333333333333C6.288386666666666 13.665333333333333 4.794879999999999 13.578333333333333 3.7397666666666667 13.492799999999999C2.541373333333333 13.395599999999998 1.5922066666666668 12.468633333333333 1.4840200000000001 11.265266666666665C1.4061199999999998 10.3988 1.3333333333333333 9.253866666666667 1.3333333333333333 7.998666666666666C1.3333333333333333 6.743533333333333 1.4061199999999998 5.598579999999999 1.4840200000000001 4.732153333333333C1.5922066666666668 3.5287466666666667 2.541373333333333 2.601793333333333 3.7397666666666667 2.50462z"
fill="currentColor"></path>
<path
d="M10.583333333333332 7.166666666666666L6.583333333333333 7.166666666666666C6.307193333333332 7.166666666666666 6.083333333333333 6.942799999999999 6.083333333333333 6.666666666666666C6.083333333333333 6.390526666666666 6.307193333333332 6.166666666666666 6.583333333333333 6.166666666666666L10.583333333333332 6.166666666666666C10.859466666666666 6.166666666666666 11.083333333333332 6.390526666666666 11.083333333333332 6.666666666666666C11.083333333333332 6.942799999999999 10.859466666666666 7.166666666666666 10.583333333333332 7.166666666666666z"
fill="currentColor"></path>
<path
d="M11.583333333333332 9.833333333333332L7.583333333333333 9.833333333333332C7.3072 9.833333333333332 7.083333333333333 9.609466666666666 7.083333333333333 9.333333333333332C7.083333333333333 9.0572 7.3072 8.833333333333332 7.583333333333333 8.833333333333332L11.583333333333332 8.833333333333332C11.859466666666666 8.833333333333332 12.083333333333332 9.0572 12.083333333333332 9.333333333333332C12.083333333333332 9.609466666666666 11.859466666666666 9.833333333333332 11.583333333333332 9.833333333333332z"
fill="currentColor"></path>
<path
d="M5.25 6.666666666666666C5.25 6.942799999999999 5.02614 7.166666666666666 4.75 7.166666666666666L4.416666666666666 7.166666666666666C4.140526666666666 7.166666666666666 3.9166666666666665 6.942799999999999 3.9166666666666665 6.666666666666666C3.9166666666666665 6.390526666666666 4.140526666666666 6.166666666666666 4.416666666666666 6.166666666666666L4.75 6.166666666666666C5.02614 6.166666666666666 5.25 6.390526666666666 5.25 6.666666666666666z"
fill="currentColor"></path>
<path
d="M6.25 9.333333333333332C6.25 9.609466666666666 6.02614 9.833333333333332 5.75 9.833333333333332L5.416666666666666 9.833333333333332C5.140526666666666 9.833333333333332 4.916666666666666 9.609466666666666 4.916666666666666 9.333333333333332C4.916666666666666 9.0572 5.140526666666666 8.833333333333332 5.416666666666666 8.833333333333332L5.75 8.833333333333332C6.02614 8.833333333333332 6.25 9.0572 6.25 9.333333333333332z"
fill="currentColor"></path>
</svg>
<span>${archive.stat.danmaku}</span>
</div>
</div>
</div>
</div>
`;
link = `请将$替换为. www$bilibili$com/video/${archive.bvid}`;
break;
}
case DYNAMIC_TYPE_LIVE: return [`${upName}发起了直播预约,我暂时无法渲染,请自行查看`, link];
case DYNAMIC_TYPE_MEDIALIST: return [`${upName}分享了收藏夹,我暂时无法渲染,请自行查看`, link];
case DYNAMIC_TYPE_PGC: return [`${upName}发布了剧集(番剧、电影、纪录片),我暂时无法渲染,请自行查看`, link];
case DYNAMIC_TYPE_ARTICLE: return [`${upName}投稿了新专栏,我暂时无法渲染,请自行查看`, link];
case DYNAMIC_TYPE_MUSIC: return [`${upName}发行了新歌,我暂时无法渲染,请自行查看`, link];
case DYNAMIC_TYPE_COMMON_SQUARE: return [`${upName}发布了装扮|剧集|点评|普通分享,我暂时无法渲染,请自行查看`, link];
case DYNAMIC_TYPE_COURSES_SEASON: return [`${upName}发布了新课程,我暂时无法渲染,请自行查看`, link];
case DYNAMIC_TYPE_UGC_SEASON: return [`${upName}更新了合集,我暂时无法渲染,请自行查看`, link];
case DYNAMIC_TYPE_NONE: return [`${upName}发布了一条无效动态`, link];
// 直播开播,不做处理
case DYNAMIC_TYPE_LIVE_RCMD: throw new Error('直播开播动态,不做处理');
case DYNAMIC_TYPE_SUBSCRIPTION_NEW:
case DYNAMIC_TYPE_BANNER:
case DYNAMIC_TYPE_SUBSCRIPTION:
case DYNAMIC_TYPE_APPLET:
case DYNAMIC_TYPE_AD:
case DYNAMIC_TYPE_COURSES_BATCH:
case DYNAMIC_TYPE_COURSES:
case DYNAMIC_TYPE_COMMON_VERTICAL:
default: return [`${upName}发布了一条我无法识别的动态,请自行查看`, ''];
}
return [main, link, forwardInfo];
};
// 获取动态主要内容
const [main, link] = await getDynamicMajor(data, false);
// 加载字体
const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, 'font/HYZhengYuan-75W.ttf'));
// 判断是否开启大字体模式
let style;
if (this.giConfig.enableLargeFont) {
style = `
@font-face {
font-family: "Custom Font";
src: url(${fontURL});
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "${this.giConfig.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
}
html {
width: 800px;
height: auto;
}
.background {
width: 100%;
height: auto;
padding: 15px;
background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
overflow: hidden;
}
.base-plate {
width: 100%;
height: auto;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 15px;
border-radius: 10px;
background-color: #FFF5EE;
}
.card {
width: 100%;
height: auto;
border-radius: 5px;
padding: 15px;
overflow: hidden;
background-color: #fff;
}
.card-body {
display: flex;
padding: 15px;
}
.card .anchor-avatar {
max-width: 70px;
/* 设置最大宽度为容器宽度的100% */
max-height: 70px;
/* 设置最大高度为容器高度的90% */
margin-right: 20px;
border-radius: 10px;
}
.card .card-body .card-content {
width: 100%;
}
.card .card-body .card-content .card-header {
width: 100%;
display: flex;
justify-content: space-between;
}
.card .up-info {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 70px;
}
.card .up-info .up-name {
font-size: 27px;
}
.card .pub-time {
font-size: 20px;
color: grey;
}
.card .card-header img {
height: 50px;
}
.card .dress-up {
position: relative;
/* background-image: url('${dynamicCardUrl}');
background-size: cover; */
font-size: 17px;
}
.card .dress-up img {
max-width: 100%;
max-height: 100%;
}
.card .dress-up span {
position: absolute;
color: ${dynamicCardColor};
right: 67px;
top: 24px;
}
.card .card-topic {
display: flex;
align-items: center;
margin-top: 10px;
font-size: 20px;
color: #008AC5;
gap: 3px;
}
.card .card-details {
margin-top: 5px;
margin-bottom: 15px;
font-size: 22px;
width: 90%;
}
.card .card-major {
display: flex;
flex-wrap: wrap;
gap: 5px;
}
.card .card-major .photo-item {
border-radius: 10px;
overflow: hidden;
width: 170px;
height: 170px;
object-fit: cover;
}
.card .card-major .single-photo-mask {
position: absolute;
text-align: center;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, transparent 30%);
}
.card .card-major .single-photo-mask-text {
position: absolute;
color: #fff;
font-size: 24px;
right: 0;
bottom: 66px;
left: 0;
text-align: center;
}
.card .card-major .single-photo-mask-arrow {
position: absolute;
width: 70px;
height: 70px;
bottom: 7px;
left: 50%;
transform: translateX(-50%);
}
.card .card-major .single-photo-container {
position: relative;
max-width: 500px;
max-height: 1000px;
border-radius: 10px;
overflow: hidden;
}
.card .card-major .single-photo-item {
max-width: 500px;
border-radius: 10px;
overflow: hidden;
}
.card .card-major .four-photo-item {
width: 170px;
height: 170px;
object-fit: cover;
border-radius: 10px;
overflow: hidden;
flex-basis: 20%; /* or any value less than 50% */
}
.card .card-stat {
display: flex;
justify-content: space-between;
width: 90%;
margin-top: 15px;
color: gray;
font-size: 14px;
}
.card .card-stat .stat-item {
display: flex;
align-items: center;
gap: 3px;
}
.card .card-video {
display: flex;
overflow: hidden;
border-radius: 5px 0 0 5px;
margin-top: 10px;
height: 147px;
}
.card .video-cover {
position: relative;
flex: 2;
overflow: hidden;
}
.card .video-cover img {
width: 236px;
}
.card .cover-mask {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: linear-gradient(to top, rgba(0, 0, 0, 0.5) 0%, transparent 30%);
}
.card .video-cover span {
position: absolute;
color: #fff;
font-size: 14px;
right: 10px;
bottom: 8px;
}
.card .video-info {
display: flex;
justify-content: space-between;
flex-direction: column;
flex: 3;
border: #e5e7e9 1px solid;
border-left: none;
border-radius: 0 5px 5px 0;
padding: 12px 16px 10px;
background-color: #fff;