MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / downloadAndUploadVideo

Method downloadAndUploadVideo

search/search.ts:597–641  ·  view source on GitHub ↗
(originalMsg: Api.Message, video: Api.Message, spoiler: boolean = false, caption?: string | null)

Source from the content-addressed store, hash-verified

595 }
596
597 private async downloadAndUploadVideo(originalMsg: Api.Message, video: Api.Message, spoiler: boolean = false, caption?: string | null): Promise<void> {
598 const tempDir = path.join(process.cwd(), "temp");
599 await fs.mkdir(tempDir, { recursive: true });
600 const tempFilePath = path.join(tempDir, `video_${Date.now()}.mp4`);
601 const statusMsg = await this.client.sendMessage(originalMsg.chatId!, { message: `🔥 正在下载视频...`, replyTo: originalMsg.id });
602
603 try {
604 await this.client.downloadMedia(video.media!, { outputFile: tempFilePath });
605 await statusMsg.edit({ text: `✅ 下载完成,正在上传...` });
606
607 if (!video.video) throw new Error("消息不包含有效的视频媒体。");
608 const fileStat = await fs.stat(tempFilePath);
609 const fileToUpload = new CustomFile(path.basename(tempFilePath), fileStat.size, tempFilePath);
610
611 const videoAttr = video.video.attributes.find((attr: any): attr is Api.DocumentAttributeVideo => attr instanceof Api.DocumentAttributeVideo);
612
613 await this.client.sendFile(originalMsg.peerId, {
614 file: fileToUpload,
615 caption: caption || video.message || "",
616 forceDocument: false,
617 spoiler: spoiler,
618 attributes: [
619 new Api.DocumentAttributeVideo({
620 duration: videoAttr?.duration || 0,
621 w: videoAttr?.w || 0,
622 h: videoAttr?.h || 0,
623 supportsStreaming: true,
624 }),
625 new Api.DocumentAttributeFilename({ fileName: fileToUpload.name }),
626 ],
627 replyTo: originalMsg.id
628 });
629 await statusMsg.delete();
630 if (originalMsg.out) await originalMsg.delete();
631 } catch (error: any) {
632 console.error("下载上传视频时出错:", error);
633 await statusMsg.edit({ text: `❌ 发送视频失败: ${error.message}` });
634 } finally {
635 try {
636 await fs.unlink(tempFilePath);
637 } catch (cleanupError) {
638 console.warn("清理临时文件失败:", cleanupError);
639 }
640 }
641 }
642
643 private isMessageMatching(message: Api.Message, query: string): boolean {
644 const normalizedQuery = this.normalizeSearchTerm(query);

Callers 1

sendVideoMethod · 0.95

Calls 5

errorMethod · 0.80
warnMethod · 0.80
downloadMediaMethod · 0.45
editMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected