mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge branch 'no-ffprobe' into dev
This commit is contained in:
commit
8afe0af940
@ -203,7 +203,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) {
|
||||
|
@ -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<SendVideoElement> {
|
||||
static async video(filePath: string, fileName: string = "", diyThumbPath: string=""): Promise<SendVideoElement> {
|
||||
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<string>((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()
|
||||
|
@ -430,7 +430,14 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
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) {
|
||||
|
@ -117,6 +117,7 @@ export interface OB11MessageText {
|
||||
|
||||
interface OB11MessageFileBase {
|
||||
data: {
|
||||
thumb?: string;
|
||||
name?: string;
|
||||
file: string,
|
||||
url?: string;
|
||||
|
Loading…
x
Reference in New Issue
Block a user