test: try to send video element

This commit is contained in:
linyuchen 2024-03-12 08:32:51 +08:00
parent 6e71cd6064
commit 2b796e33fe
5 changed files with 112 additions and 38 deletions

BIN
icon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -1,15 +1,18 @@
import { import {
AtType, AtType,
ElementType, PicType, SendArkElement, ElementType,
PicType,
SendArkElement,
SendFaceElement, SendFaceElement,
SendFileElement, SendFileElement,
SendPicElement, SendPicElement,
SendPttElement, SendPttElement,
SendReplyElement, SendReplyElement,
SendTextElement SendTextElement,
SendVideoElement
} from "./types"; } from "./types";
import {NTQQApi} from "./ntcall"; import {NTQQApi} from "./ntcall";
import {encodeSilk, isGIF} from "../common/utils"; import {encodeSilk, isGIF, log} from "../common/utils";
import * as fs from "node:fs"; import * as fs from "node:fs";
@ -84,13 +87,9 @@ export class SendMsgElementConstructor {
}; };
} }
static async file(filePath: string, showPreview: boolean = false, fileName: string = ""): Promise<SendFileElement> { static async file(filePath: string, fileName: string = ""): Promise<SendFileElement> {
let picHeight = 0; let picHeight = 0;
let picWidth = 0; let picWidth = 0;
if (showPreview) {
picHeight = 1024;
picWidth = 768;
}
const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE); const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
if (fileSize === 0) { if (fileSize === 0) {
throw "文件异常大小为0"; throw "文件异常大小为0";
@ -102,16 +101,80 @@ export class SendMsgElementConstructor {
fileName: fileName || _fileName, fileName: fileName || _fileName,
"filePath": path, "filePath": path,
"fileSize": (fileSize).toString(), "fileSize": (fileSize).toString(),
picHeight,
picWidth
} }
} }
return element; return element;
} }
static video(filePath: string, fileName: string=""): Promise<SendFileElement> { static async video(filePath: string, fileName: string = ""): Promise<SendVideoElement> {
return SendMsgElementConstructor.file(filePath, true, fileName); const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.VIDEO);
if (fileSize === 0) {
throw "文件异常大小为0";
}
log("上传视频", md5, path, fileSize, fileName || _fileName)
let thumbPath = new Map()
thumbPath.set(0, "E:\\SystemDocuments\\QQ\\721011692\\nt_qq\\nt_data\\Video\\2024-03\\Thumb\\8950eb327e26c01e69d4a0fab7e2b159_0.png")
let element: SendVideoElement = {
elementType: ElementType.VIDEO,
elementId: "",
videoElement: {
fileName: fileName || _fileName,
filePath: path,
videoMd5: md5,
"thumbMd5": "9eee9e9a07b193cbaf4846522b0197b4",
fileTime: 15,
thumbPath: thumbPath,
"thumbSize": 368286,
"fileFormat": 2,
"thumbWidth": 540,
"thumbHeight": 960,
// "busiType": 0,
// "subBusiType": 0,
// fileUuid: md5,
fileSize: "" + fileSize,
"transferStatus": 0,
"progress": 0,
"invalidState": 0,
// "fileUuid": "3051020100043630340201000204169df3d602037a1afd020440f165b4020465f02cb304108950eb327e26c01e69d4a0fab7e2b15802037a1db902010004140000000866696c65747970650000000431303031",
"fileSubId": "",
"fileBizId": null,
"originVideoMd5": "",
"import_rich_media_context": null,
"sourceVideoCodecFormat": 0
}
}
return element;
log("video element", element)
let e = {
"elementType": 5,
"elementId": "",
"videoElement": {
"filePath": "E:\\SystemDocuments\\QQ\\721011692\\nt_qq\\nt_data\\Video\\2024-03\\Ori\\8950eb327e26c01e69d4a0fab7e2b158.mp4",
"fileName": "8950eb327e26c01e69d4a0fab7e2b158.mp4",
"videoMd5": "8950eb327e26c01e69d4a0fab7e2b158",
"thumbMd5": "9eee9e9a07b193cbaf4846522b0197b4",
"fileTime": 15,
"thumbSize": 368286,
"fileFormat": 2,
"fileSize": "2084867",
"thumbWidth": 540,
"thumbHeight": 960,
"busiType": 0,
"subBusiType": 0,
"thumbPath": thumbPath,
"transferStatus": 0,
"progress": 0,
"invalidState": 0,
"fileUuid": "3051020100043630340201000204169df3d602037a1afd020440f165b4020465f02cb304108950eb327e26c01e69d4a0fab7e2b15802037a1db902010004140000000866696c65747970650000000431303031",
"fileSubId": "",
"fileBizId": null,
"originVideoMd5": "",
"import_rich_media_context": null,
"sourceVideoCodecFormat": 0
}
}
return e as SendVideoElement
} }
static async ptt(pttPath: string): Promise<SendPttElement> { static async ptt(pttPath: string): Promise<SendPttElement> {

View File

@ -224,6 +224,10 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload
continue continue
} }
for (const msgElement of message.elements) { for (const msgElement of message.elements) {
if (msgElement.videoElement) {
log("收到视频消息", msgElement.videoElement)
log("視頻缩略图", msgElement.videoElement.thumbPath.get(0));
}
setTimeout(() => { setTimeout(() => {
const picPath = msgElement.picElement?.sourcePath const picPath = msgElement.picElement?.sourcePath
const pttPath = msgElement.pttElement?.filePath const pttPath = msgElement.pttElement?.filePath
@ -235,6 +239,7 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload
if (aioOpGrayTipElement){ if (aioOpGrayTipElement){
tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat; tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat;
} }
// log("需要清理的文件", pathList); // log("需要清理的文件", pathList);
for (const path of pathList) { for (const path of pathList) {
if (path) { if (path) {

View File

@ -71,6 +71,7 @@ export enum ElementType {
PIC = 2, PIC = 2,
FILE = 3, FILE = 3,
PTT = 4, PTT = 4,
VIDEO = 5,
FACE = 6, FACE = 6,
REPLY = 7, REPLY = 7,
ARK = 10, ARK = 10,
@ -167,11 +168,16 @@ export interface FileElement {
} }
export interface SendFileElement { export interface SendFileElement {
elementType: ElementType.FILE, elementType: ElementType.FILE
elementId: "", elementId: "",
fileElement: FileElement fileElement: FileElement
} }
export interface SendVideoElement {
elementType: ElementType.VIDEO
elementId: "",
videoElement: VideoElement
}
export interface SendArkElement { export interface SendArkElement {
elementType: ElementType.ARK, elementType: ElementType.ARK,
elementId: "", elementId: "",
@ -180,7 +186,7 @@ export interface SendArkElement {
} }
export type SendMessageElement = SendTextElement | SendPttElement | export type SendMessageElement = SendTextElement | SendPttElement |
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement | SendArkElement SendPicElement | SendReplyElement | SendFaceElement | SendFileElement | SendVideoElement | SendArkElement
export enum AtType { export enum AtType {
notAt = 0, notAt = 0,
@ -258,26 +264,26 @@ export interface FaceElement {
export interface VideoElement { export interface VideoElement {
"filePath": string, "filePath": string,
"fileName": string, "fileName": string,
"videoMd5": string, "videoMd5"?: string,
"thumbMd5": string "thumbMd5"?: string
"fileTime": 87, // second "fileTime"?: number, // second
"thumbSize": 314235, // byte "thumbSize"?: number, // byte
"fileFormat": 2, // 2表示mp4 "fileFormat"?: number, // 2表示mp4
"fileSize": string, // byte "fileSize"?: string, // byte
"thumbWidth": number, "thumbWidth"?: number,
"thumbHeight": number, "thumbHeight"?: number,
"busiType": 0, // 未知 "busiType"?: 0, // 未知
"subBusiType": 0, // 未知 "subBusiType"?: 0, // 未知
"thumbPath": Map<number, any>, "thumbPath"?: Map<number, any>,
"transferStatus": 0, // 未知 "transferStatus"?: 0, // 未知
"progress": 0, // 下载进度? "progress"?: 0, // 下载进度?
"invalidState": 0, // 未知 "invalidState"?: 0, // 未知
"fileUuid": string, // 可以用于下载链接? "fileUuid"?: string, // 可以用于下载链接?
"fileSubId": "", "fileSubId"?: "",
"fileBizId": null, "fileBizId"?: null,
"originVideoMd5": "", "originVideoMd5"?: "",
"import_rich_media_context": null, "import_rich_media_context"?: null,
"sourceVideoCodecFormat": 0 "sourceVideoCodecFormat"?: 0
} }
export interface TipAioOpGrayTipElement { // 这是什么提示来着? export interface TipAioOpGrayTipElement { // 这是什么提示来着?

View File

@ -372,7 +372,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
} }
if (sendMsg.type === OB11MessageDataType.file) { if (sendMsg.type === OB11MessageDataType.file) {
log("发送文件", path, payloadFileName || fileName) log("发送文件", path, payloadFileName || fileName)
sendElements.push(await SendMsgElementConstructor.file(path, false, payloadFileName || fileName)); sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
} else if (sendMsg.type === OB11MessageDataType.video) { } else if (sendMsg.type === OB11MessageDataType.video) {
log("发送视频", path, payloadFileName || fileName) log("发送视频", path, payloadFileName || fileName)
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName)); sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName));