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

@@ -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}` : "")
]);
});