extended mime check and failsafe
All checks were successful
fetch npm modules / f0ck the f0cker (push) Successful in 44s
All checks were successful
fetch npm modules / f0ck the f0cker (push) Successful in 44s
This commit is contained in:
parent
e0ac02e742
commit
b95ce804ab
|
@ -51,13 +51,24 @@ export default async bot => {
|
||||||
|
|
||||||
const maxfilesize = (getLevel(e.user).level > 50 ? cfg.main.maxfilesize * cfg.main.adminmultiplier : cfg.main.maxfilesize);
|
const maxfilesize = (getLevel(e.user).level > 50 ? cfg.main.maxfilesize * cfg.main.adminmultiplier : cfg.main.maxfilesize);
|
||||||
|
|
||||||
let ext;
|
|
||||||
// read metadata
|
// read metadata
|
||||||
if(!regex.yt.test(link)) {
|
/*if(!regex.yt.test(link)) {
|
||||||
const tmphead = (await fetch(link, { method: "HEAD" })).headers["content-type"];
|
const tmphead = (await fetch(link, { method: "HEAD" })).headers["content-type"];
|
||||||
if(!Object.keys(cfg.mimes).includes(tmphead))
|
if(!Object.keys(cfg.mimes).includes(tmphead))
|
||||||
return;
|
return;
|
||||||
ext = cfg.mimes[tmphead];
|
ext = cfg.mimes[tmphead];
|
||||||
|
}*/
|
||||||
|
let ext;
|
||||||
|
try {
|
||||||
|
const meta = JSON.parse((await queue.exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' --skip-download --dump-json "${link}"`)).stdout);
|
||||||
|
ext = meta.ext;
|
||||||
|
} catch(err) {
|
||||||
|
const tmphead = (await fetch(link, { method: "HEAD" })).headers["content-type"];
|
||||||
|
ext = tmphead;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Object.values(cfg.mimes).includes(ext.toLowerCase())) {
|
||||||
|
return await e.reply('mime schmime '+ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
const msg = await e.reply(`[charging the f0cker] downloading: ${uuid}`, {
|
const msg = await e.reply(`[charging the f0cker] downloading: ${uuid}`, {
|
||||||
|
@ -66,7 +77,14 @@ export default async bot => {
|
||||||
|
|
||||||
// download data
|
// download data
|
||||||
const start = new Date();
|
const start = new Date();
|
||||||
let source = (await queue.exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' "${link}" --max-filesize ${maxfilesize / 1024}k --postprocessor-args "ffmpeg:-bitexact" -o "./tmp/${uuid}.%(ext)s" --print after_move:filepath`)).stdout.trim();
|
let source;
|
||||||
|
try {
|
||||||
|
source = (await queue.exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' "${link}" --max-filesize ${maxfilesize / 1024}k --postprocessor-args "ffmpeg:-bitexact" -o "./tmp/${uuid}.%(ext)s" --print after_move:filepath --merge-output-format "mp4"`)).stdout.trim();
|
||||||
|
} catch(err) {
|
||||||
|
if(e.type == 'tg')
|
||||||
|
return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "something went wrong lol");
|
||||||
|
return await e.reply("something went wrong lol");
|
||||||
|
}
|
||||||
|
|
||||||
if(!source) {
|
if(!source) {
|
||||||
if(e.type == 'tg')
|
if(e.type == 'tg')
|
||||||
|
@ -91,8 +109,28 @@ export default async bot => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// mime check
|
// mime check
|
||||||
const mime = (await queue.exec(`file --mime-type -b ${source}`)).stdout.trim();
|
let mime = (await queue.exec(`file --mime-type -b ${source}`)).stdout.trim();
|
||||||
|
try {
|
||||||
|
if(mime == 'video/x-matroska') { // mkv failsafe
|
||||||
|
await queue.exec(`ffmpeg -i ./tmp/${uuid}.mkv -codec copy ./tmp/${uuid}.mp4`);
|
||||||
|
await fs.promises.unlink(source);
|
||||||
|
source = source.replace(/\.mkv$/, '.mp4');
|
||||||
|
mime = 'video/mp4';
|
||||||
|
}
|
||||||
|
if(source.match(/\.opus$/)) { // opus failsave
|
||||||
|
await queue.exec(`ffmpeg -i ./tmp/${uuid}.opus -codec copy ./tmp/${uuid}.ogg`);
|
||||||
|
await fs.promises.unlink(source);
|
||||||
|
source = source.replace(/\.opus$/, '.ogg');
|
||||||
|
mime = 'audio/ogg';
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
if(e.type == 'tg')
|
||||||
|
return await e.editMessageText(msg.result.chat.id, msg.result.message_id, "something went wrong lol");
|
||||||
|
return await e.reply("something went wrong lol");
|
||||||
|
}
|
||||||
|
|
||||||
if(!Object.keys(cfg.mimes).includes(mime)) {
|
if(!Object.keys(cfg.mimes).includes(mime)) {
|
||||||
|
await fs.promises.unlink(source).catch(_=>{});
|
||||||
if(e.type == 'tg')
|
if(e.type == 'tg')
|
||||||
return await e.editMessageText(msg.result.chat.id, msg.result.message_id, `lol, go f0ck yourself (${mime})`);
|
return await e.editMessageText(msg.result.chat.id, msg.result.message_id, `lol, go f0ck yourself (${mime})`);
|
||||||
return await e.reply(`lol, go f0ck yourself (${mime})`);
|
return await e.reply(`lol, go f0ck yourself (${mime})`);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user