From 92a2d8b5e2a827a357b2fd40392aeba8f108fe72 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Tue, 19 Mar 2024 14:57:38 +0800 Subject: [PATCH] test no ffmpeg --- src/common/utils/file.ts | 9 ++++++++- src/ntqqapi/constructor.ts | 12 ++++++++++-- src/onebot11/action/SendMsg.ts | 9 ++++++++- src/onebot11/types.ts | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/common/utils/file.ts b/src/common/utils/file.ts index f473aef..ade4170 100644 --- a/src/common/utils/file.ts +++ b/src/common/utils/file.ts @@ -194,7 +194,14 @@ export async function getVideoInfo(filePath: string) { }>((resolve, reject) => { ffmpeg(filePath).ffprobe((err, metadata) => { if (err) { - reject(err); + resolve({ + width: 720, height: 1080, + time: 15, + format: "mp4", + size: fs.statSync(filePath).size, + filePath + }) + // reject(err); } else { const videoStream = metadata.streams.find(s => s.codec_type === 'video'); if (videoStream) { diff --git a/src/ntqqapi/constructor.ts b/src/ntqqapi/constructor.ts index 679f173..0ef1077 100644 --- a/src/ntqqapi/constructor.ts +++ b/src/ntqqapi/constructor.ts @@ -17,6 +17,7 @@ import {NTQQFileApi} from "./api/file"; import {calculateFileMD5, encodeSilk, getVideoInfo, isGIF} from "../common/utils/file"; import {log} from "../common/utils/log"; import {sleep} from "../common/utils/helper"; +import pathLib from "path"; export class SendMsgElementConstructor { @@ -108,7 +109,7 @@ export class SendMsgElementConstructor { return element; } - static async video(filePath: string, fileName: string = ""): Promise { + static async video(filePath: string, fileName: string = "", diyThumbPath: string=""): Promise { let {fileName: _fileName, path, fileSize, md5} = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO); if (fileSize === 0) { throw "文件异常,大小为0"; @@ -126,6 +127,13 @@ export class SendMsgElementConstructor { log("视频信息", videoInfo) const createThumb = new Promise((resolve, reject) => { const thumbFileName = `${md5}_0.png` + const thumbPath = pathLib.join(thumb, thumbFileName) + if (diyThumbPath) { + fs.copyFile(diyThumbPath, pathLib.join(thumb, thumbFileName)).then(() => { + resolve(thumbPath); + }) + return; + } ffmpeg(filePath) .on("end", () => { }) @@ -138,7 +146,7 @@ export class SendMsgElementConstructor { folder: thumb, size: videoInfo.width + "x" + videoInfo.height }).on("end", () => { - resolve(pathLib.join(thumb, thumbFileName)); + resolve(thumbPath); }); }) let thumbPath = new Map() diff --git a/src/onebot11/action/SendMsg.ts b/src/onebot11/action/SendMsg.ts index b7eb2fa..b3b4f7f 100644 --- a/src/onebot11/action/SendMsg.ts +++ b/src/onebot11/action/SendMsg.ts @@ -430,7 +430,14 @@ export class SendMsg extends BaseAction { sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName)); } else if (sendMsg.type === OB11MessageDataType.video) { log("发送视频", path, payloadFileName || fileName) - sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName)); + let thumb = sendMsg.data?.thumb; + if (thumb){ + let uri2LocalRes = await uri2local(thumb) + if (uri2LocalRes.success){ + thumb = uri2LocalRes.path; + } + } + sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb)); } else if (sendMsg.type === OB11MessageDataType.voice) { sendElements.push(await SendMsgElementConstructor.ptt(path)); }else if (sendMsg.type === OB11MessageDataType.image) { diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index b8db420..99071ea 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -115,6 +115,7 @@ export interface OB11MessageText { interface OB11MessageFileBase { data: { + thumb?: string; name?: string; file: string, url?: string;