parser die Zweite

This commit is contained in:
Flummi 2018-09-03 18:20:27 +02:00
parent e62de626b4
commit 2c832f2014

View File

@ -40,7 +40,18 @@ export default bot => {
link: data.webpage_url, link: data.webpage_url,
file: data.id, file: data.id,
format: data.formats format: data.formats
.filter(f => (f.filesize <= cfg.main.maxFileSize.val || f.ext === "mp3") && ["webm","mp4","mp3"].includes(f.ext)) .filter(f => {
if(f.hasOwnProperty("fragments"))
return false;
if(!["webm", "mp4", "mp3"].includes(f.ext))
return false;
if(f.filesize > cfg.main.maxFileSize.val && f.ext !== "mp3")
return false;
if(/playlist/i.test(f.url))
return false;
//e.reply(`${f.ext} - ${f.url} - ${f.format}`);
return f;
})
.splice(-1, 1) .splice(-1, 1)
.map(f => ({ .map(f => ({
ext: f.ext, ext: f.ext,
@ -56,14 +67,39 @@ export default bot => {
fetch(data.format[0].url, { size: cfg.main.maxFileSize.val }) fetch(data.format[0].url, { size: cfg.main.maxFileSize.val })
.then(res => { .then(res => {
const uuid = lib.getUUID(); const uuid = lib.getUUID();
const dest = fs.createWriteStream(b + "/" + uuid + "." + data.format[0].ext); const file = `${b}/${uuid}.${data.format[0].ext}`;
const dest = fs.createWriteStream(file);
res.body.pipe(dest); res.body.pipe(dest);
e.reply(`gef0ckt lol: ${data.file} -> ${uuid}.${data.format[0].ext}, ~${data.format[0].size}`); let t;
dest.on("open", () => {
e.reply(`downloading ${data.file}...`);
t = setInterval(() => {
const size = fs.statSync(file).size;
if(size >= cfg.main.maxFileSize.val) {
e.reply(`file too large lol! D: (${lib.formatSize(size)})`);
res.body.unpipe(dest);
dest.destroy();
fs.unlinkSync(file);
clearInterval(t);
t = false;
}
}, 2000);
});
dest.on("close", blah => {
if(t) {
clearInterval(t);
e.reply(`gef0ckt lol: ${data.file} -> ${uuid}.${data.format[0].ext}, ~${lib.formatSize(fs.statSync(file).size)}`);
}
else {
// recursive
}
});
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
}); });
})); }).catch(err => e.reply(JSON.stringify(err)))
);
} }
})); }));
}; };