autotagger

This commit is contained in:
Flummi 2021-12-23 06:07:19 +01:00
parent 2c80c58f59
commit 885d729a76
3 changed files with 45 additions and 7 deletions

View File

@ -0,0 +1,15 @@
const auth = async (req, res, next) => {
if(!req.session)
return res.redirect("/login");
return next();
};
export default (router, tpl) => {
router.group(/^\/settings/, group => {
group.get(/$/, auth, (req, res) => {
res.end("settings lol");
});
});
return router;
};

View File

@ -1,3 +1,4 @@
import fetch from "flumm-fetch-cookies";
import { promises as fs } from "fs";
import { exec } from "child_process";
import cfg from "../config.mjs";
@ -92,6 +93,16 @@ export default async bot => {
const tmpc = await countf0cks();
e.reply(`tagged: ${tmpc.tagged}; untagged: ${tmpc.untagged}; sfw: ${tmpc.sfw}; nsfw: ${tmpc.nsfw}; total: ${tmpc.total}`);
break;
case "autotagger":
const body = { headers: { Authorization: `Basic ${cfg.tagger.btoa}` } };
const res = await (await fetch(`${cfg.tagger.endpoint}/usage`, body)).json();
if(res) {
const processed = res.result.monthly_processed;
const limit = res.result.monthly_limit;
return e.reply(`autotagger: usage/limit: ${processed}/${limit}`);
}
return;
break;
case "help":
e.reply("cmds: stats, limit, thumb, cache, uptime, restart, cleanTags, clearTmp, status");
break;

View File

@ -60,8 +60,8 @@ export default async bot => {
meta = JSON.parse((await exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' --skip-download --dump-json "${link}"`)).stdout);
}
catch(err) {
e.reply("[error] f0ck has no bock :(");
console.error(err);
//e.reply("[error] f0ck has no bock :(");
//console.error(err);
return;
}
@ -74,7 +74,6 @@ export default async bot => {
let filename = `${uuid}.${meta.ext}`;
//e.reply(`downloading ${uuid}...`);
e.reply(`[charging the f0cker] downloading: ${uuid}`);
// download data
@ -83,14 +82,11 @@ export default async bot => {
if(meta.ext === "mp4") {
source = (await exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' "${link}" --max-filesize ${maxfilesize}k --merge-output-format mp4 -o ./tmp/${filename}`)).stdout.trim();
//change yt-dlp to youtube-dl if problem ^
//console.log("mp4 lol");
}
else {
source = (await exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' "${link}" --max-filesize ${maxfilesize}k -o ./tmp/${filename}`)).stdout.trim();
//change yt-dlp to youtube-dl if problem ^
//console.log("alles andere lol");
}
//console.log(source);
if(source.match(/larger than/))
return e.reply("too large lol");
@ -158,8 +154,24 @@ export default async bot => {
let speed = lib.calcSpeed(size, end);
speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`;
// tagger
let tag;
if(mime.startsWith("image")) {
const body = { headers: { Authorization: `Basic ${cfg.tagger.btoa}` } };
const res = await (await fetch(`${cfg.tagger.endpoint}/categories/nsfw_beta?image_url=${cfg.main.url}/b/${filename}`, body)).json();
if(res) {
tag = (res.result.categories[0].name.en === "safe") ? "sfw" : "nsfw";
await sql("tags_assign").insert({
tag_id: tag === "sfw" ? 1 : 2,
item_id: insertq,
prefix: `autotagger`
});
}
}
e.reply([
`[f0cked] link: ${cfg.main.url}/${insertq} | size: ${lib.formatSize(size)} | speed: ${speed}`
`[f0cked] link: ${cfg.main.url}/${insertq} | size: ${lib.formatSize(size)} | speed: ${speed}` + (tag ? ` | ${tag}` : "")
]);
});