youtube-dl

This commit is contained in:
Flummi 2021-02-10 11:16:30 +01:00
parent 2a10fd2e93
commit de0a0e2303

View File

@ -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");
@ -81,6 +79,29 @@ export default async bot => {
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 ]);
if(q_repostc.length > 0)