ja
This commit is contained in:
@ -18,12 +18,20 @@ export default async bot => {
|
||||
f: e => {
|
||||
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
|
||||
|
||||
const trigger = [...bot._trigger.entries()].filter(t =>
|
||||
t[1].call.exec(e.message) &&
|
||||
t[1].clients.includes(e.type) &&
|
||||
t[1].active &&
|
||||
t[1].level <= getLevel(e.user).level
|
||||
);
|
||||
let trigger;
|
||||
|
||||
if(e.photo) {
|
||||
trigger = [...bot._trigger.entries()].filter(t => t[1].name === "parser");
|
||||
if(!e.message)
|
||||
e.message = "";
|
||||
} else {
|
||||
trigger = [...bot._trigger.entries()].filter(t =>
|
||||
t[1].call.exec(e.message) &&
|
||||
t[1].clients.includes(e.type) &&
|
||||
t[1].active &&
|
||||
t[1].level <= getLevel(e.user).level
|
||||
);
|
||||
}
|
||||
|
||||
trigger.forEach(async t => {
|
||||
try {
|
||||
@ -31,6 +39,7 @@ export default async bot => {
|
||||
console.log(`triggered > ${t[0]}`);
|
||||
}
|
||||
catch(err) {
|
||||
console.error(err);
|
||||
e.reply(`${t[0]}: An error occured.`);
|
||||
logger.error(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${err.toString ? err : JSON.stringify(err)}`);
|
||||
}
|
||||
|
@ -3,6 +3,6 @@ export default new class {
|
||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + " " + ["B", "kB", "MB", "GB", "TB"][i];
|
||||
}
|
||||
calcSpeed(b, s) {
|
||||
return `${(Math.round((b * 8 / s / 1e6) * 1e4) / 1e4).toFixed(2)} Mbit/s`;
|
||||
return (Math.round((b * 8 / s / 1e6) * 1e4) / 1e4);
|
||||
}
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ router.get("/", async (req, res) => {
|
||||
router.get(/^\/([0-9]+)$/, async (req, res) => {
|
||||
const query = (await sql.query(queries.item, Array(3).fill(req.url.split[0])))?.shift();
|
||||
|
||||
if(query.length === 0)
|
||||
if(!query?.id)
|
||||
return res.redirect("/404");
|
||||
|
||||
const data = {
|
||||
|
@ -17,11 +17,12 @@ export default async bot => {
|
||||
call: regex,
|
||||
active: true,
|
||||
f: e => {
|
||||
const links = e.message.match(regex)?.filter(link => {
|
||||
return (
|
||||
!link.includes("f0ck.me")
|
||||
);
|
||||
});
|
||||
const links = e.message.match(regex)?.filter(link => !link.includes("f0ck.me")) || [];
|
||||
|
||||
if(e.photo) {
|
||||
links.push(e.photo);
|
||||
}
|
||||
|
||||
if(links.length === 0)
|
||||
return false;
|
||||
|
||||
@ -42,17 +43,31 @@ export default async bot => {
|
||||
// generate uuid
|
||||
const uuid = (await sql.query("select left(uuid(), 8) as uuid"))[0].uuid;
|
||||
|
||||
// read metadata
|
||||
const meta = JSON.parse((await exec(`youtube-dlc --skip-download --dump-json "${link}"`)).stdout);
|
||||
const maxfilesize = ( getLevel(e.user).level > 50 ? cfg.main.maxfilesize * 2.5 : cfg.main.maxfilesize ) / 1024;
|
||||
|
||||
const filename = `${uuid}.mp4`;
|
||||
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);
|
||||
}
|
||||
catch(e) {
|
||||
return;
|
||||
}
|
||||
|
||||
const filename = `${uuid}.${meta.ext}`;
|
||||
|
||||
e.reply(`downloading ${filename}...`);
|
||||
|
||||
// download data
|
||||
const start = new Date();
|
||||
const maxfilesize = getLevel(e.user).level > 50 ? cfg.main.maxfilesize * 2.5 : cfg.main.maxfilesize;
|
||||
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();
|
||||
//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();
|
||||
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();
|
||||
|
||||
if(source.match(/larger than/))
|
||||
return e.reply("too large lol");
|
||||
const end = ~~((new Date() - start) / 1e3);
|
||||
@ -76,15 +91,15 @@ export default async bot => {
|
||||
|
||||
const insertq = await sql.query(
|
||||
"insert into items (src, dest, mime, size, checksum, username, userchannel, usernetwork, stamp, active) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
[ link, filename, mime, size, checksum, e.user.nick || e.user.username, e.channel, e.network, ~~(new Date() / 1000), 1 ]
|
||||
[ e.photo ? "" : link, filename, mime, size, checksum, e.user.nick || e.user.username, e.channel, e.network, ~~(new Date() / 1000), 1 ]
|
||||
);
|
||||
|
||||
// generate thumbnail
|
||||
let thumb_orig = (await exec(`youtube-dlc --get-thumbnail "${link}"`)).stdout.trim();
|
||||
let thumb_orig = (await exec(`youtube-dlc -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --get-thumbnail "${link}"`)).stdout.trim();
|
||||
if(!thumb_orig.startsWith("http")) {
|
||||
if(mime.startsWith("image") && mime !== "image/gif")
|
||||
thumb_orig = `./public/b/${filename}`;
|
||||
else {
|
||||
else if(!mime.startsWith("audio")) {
|
||||
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${insertq.insertId}`);
|
||||
thumb_orig = `./tmp/${insertq.insertId}`;
|
||||
}
|
||||
@ -92,9 +107,12 @@ export default async bot => {
|
||||
await exec(`convert "${thumb_orig}" -resize "200x200^" -gravity center -crop 128x128+0+0 +repage ./public/t/${insertq.insertId}.png`);
|
||||
await fs.promises.unlink(`./tmp/${insertq.insertId}`).catch(_=>{});
|
||||
|
||||
let speed = lib.calcSpeed(size, end);
|
||||
speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`;
|
||||
|
||||
e.reply([
|
||||
`title: ${meta.fulltitle}`,
|
||||
`size: ${lib.formatSize(size)} ${lib.calcSpeed(size, end)} (ytdl: ${end})`,
|
||||
`size: ${lib.formatSize(size)} speed: ${speed}`,
|
||||
`link: ${cfg.main.url}/${insertq.insertId}`
|
||||
]);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import "./websrv.mjs";
|
||||
this.call = args.call;
|
||||
this.help = args.help || false;
|
||||
this.level = args.level || 0;
|
||||
this.name = args.name;
|
||||
this.active = args.hasOwnProperty("active") ? args.active : true;
|
||||
this.clients = args.clients || [ "irc", "tg", "slack" ];
|
||||
this.f = args.f;
|
||||
|
Reference in New Issue
Block a user