diff --git a/src/bot.js b/src/bot.js index fa90c8b..6587945 100644 --- a/src/bot.js +++ b/src/bot.js @@ -78,7 +78,9 @@ class TgBotSender { async sendVideo (chatId, data, settings = {}, apiOptions = {}) { if (this.parent.mtproto !== null) { const mtprotoMID = await this.parent.mtproto.saveMedia( - data, settings.caption ?? "" + data, settings.caption ?? "", { + thumb: settings.thumb, + } ); return await this.bot.copyMessage( @@ -157,6 +159,7 @@ class TgBotSender { .then(async (downloaded) => { //console.debug("downloaded:", downloaded); try { + const videoInfo = await video.getVideoInfo(); if (downloaded.format.type === "video") { const filesize = (typeof isStream !== "string" || this.parent.mtproto !== null) ? 0 : await getFileSize(downloaded.data); @@ -170,7 +173,10 @@ class TgBotSender { await this.sendVideo( msg.chat.id, downloaded.data, - { caption: info.title }, + { + caption: info.title, + thumb: await downloadFile(videoInfo.thumbnail), + }, { filename, contentType: isStream === true ? "application/octet-stream" : downloaded.format.mime, @@ -193,7 +199,6 @@ class TgBotSender { } MB)`); } } else if (downloaded.format.type === "audio") { - const videoInfo = await video.getVideoInfo(); await this.sendAudio( msg.chat.id, downloaded.data, diff --git a/src/mtproto.js b/src/mtproto.js index 707b082..00822df 100644 --- a/src/mtproto.js +++ b/src/mtproto.js @@ -32,7 +32,6 @@ class MTProtoUser { writeStream.on("error", reject); writeStream.on("finish", resolve); }); - //fs.writeFileSync(); } const msg = await this.client.sendFile(config.mtproto.chatId, { @@ -41,6 +40,14 @@ class MTProtoUser { thumb: options.thumb, //filename: options.filename, supportsStreaming: true, + attributes: [ + new Api.DocumentAttributeVideo({ + duration: options.duration || 0, + w: options.width || 1280, + h: options.height || 720, + supportsStreaming: true + }), + ], }); return msg.id; diff --git a/src/utils.js b/src/utils.js index 558cbd3..4f5889a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -21,18 +21,15 @@ async function downloadFile (fileUrl) { protocol.get(fileUrl, (response) => { if (response.statusCode !== 200) { - return reject( - new Error(`Failed to get '${fileUrl}' (${response.statusCode})`) - ); + return reject( + new Error(`Failed to get '${fileUrl}' (${response.statusCode})`) + ); } response.pipe(file); file.on("finish", () => { file.close(); - /*setTimeout(() => { - fs.rm(savePath, () => {}); - }, 60000);*/ resolve(savePath); }); }).on("error", (err) => {