diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index 1a0ddb1..f04b689 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -48,25 +48,23 @@ export default async bot => { let meta; // read metadata try { - //meta = JSON.parse((await exec(`youtube-dlc -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --skip-download --dump-json "${link}"`)).stdout); - meta = JSON.parse((await exec(`youtube-dlc -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --skip-download --dump-json "${link}"`)).stdout); + meta = JSON.parse((await exec(`youtube-dl -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --skip-download --dump-json "${link}"`)).stdout); } catch(e) { return; } - const filename = `${uuid}.${meta.ext}`; + let filename = `${uuid}.${meta.ext}`; - e.reply(`downloading ${filename}...`); + e.reply(`downloading ${uuid}...`); // download data const start = new Date(); - //const source = (await exec(`youtube-dlc "${link}" -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --max-filesize ${maxfilesize} -o ./tmp/${filename}`)).stdout.trim(); let source; if(meta.ext === "mp4") - source = (await exec(`youtube-dlc "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --merge-output-format mp4 -o ./tmp/${filename}`)).stdout.trim(); + source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --merge-output-format mp4 -o ./tmp/${filename}`)).stdout.trim(); else - source = (await exec(`youtube-dlc "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" -o ./tmp/${filename}`)).stdout.trim(); + source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" -o ./tmp/${filename}`)).stdout.trim(); if(source.match(/larger than/)) return e.reply("too large lol"); @@ -80,6 +78,29 @@ export default async bot => { const mime = (await exec(`file --mime-type -b ./tmp/${filename}`)).stdout.trim(); if(!cfg.allowed.includes(mime)) return e.reply(`lol, go f0ck yourself (${mime})`); + + if(!cfg.ext.includes(meta.ext)) { + let tmpext = ""; + if(mime === "image/png") + tmpext = "png"; + else if(mime === "video/webm") + tmpext = "webm"; + else if(mime === "image/gif") + tmpext = "gif"; + else if(mime === "image/jpeg") + tmpext = "jpg"; + else if(mime === "video/mp4" || mime === "video/quicktime") + tmpext = "mp4"; + else if(mime === "audio/mpeg") + tmpext = "mp3"; + else if(mime === "audio/ogg") + tmpext = "ogg"; + else if(mime === "audio/flac" || mime === "audio/x-flac") + tmpext = "flac"; + + fs.renameSync(`./tmp/${filename}`, `./tmp/${uuid}.${tmpext}`); + filename = `${uuid}.${tmpext}`; + } // check repost (checksum) const q_repostc = await sql.query("select id from items where checksum = ?", [ checksum ]);