diff --git a/src/bot.js b/src/bot.js index 8e1c90a..eea255d 100644 --- a/src/bot.js +++ b/src/bot.js @@ -6,6 +6,7 @@ const https = require("https"); const config = require("./config"); const { DownloadVideo, YtdlUpdater, downloadFile } = require("./download"); const { MTProtoUser } = require("./mtproto"); +const utils = require("./utils"); async function getImage(url) { return new Promise((resolve, reject) => { @@ -212,9 +213,9 @@ class TgBotSender { }, { //filename: `downloaded.${downloaded.format.exc}`, - filename: `${ - videoInfo.title - }.mp3`, + filename: + utils.setupCorrectFilename(videoInfo.title) + + ".mp3", contentType: downloaded.format.mime, }, ); diff --git a/src/download.js b/src/download.js index 74c278a..668b9a2 100644 --- a/src/download.js +++ b/src/download.js @@ -261,6 +261,9 @@ class DownloadVideo { async download(cb, isStream = false) { const signal = new EventEmitter(); const isPath = typeof isStream === "string"; + if (isPath) { + console.debug({ isStream }); + } if (!this.parent.updater.lock(signal)) { await new Promise((rs => { this.parent.updater.once("finish", () => { diff --git a/src/utils.js b/src/utils.js index 4f5889a..bba7af8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -52,4 +52,8 @@ async function verifyThumbUrl (fileUrl) { } } -module.exports = { downloadFile, verifyThumbUrl }; +function setupCorrectFilename (filename) { + return filename.replace(/[\/\\\s\.+]{1,}/g, "_"); +} + +module.exports = { downloadFile, verifyThumbUrl, setupCorrectFilename };