autotagger v2 lol
This commit is contained in:
@ -1,33 +1,77 @@
|
||||
import sql from "../src/inc/sql.mjs";
|
||||
import cfg from "../src/inc/config.mjs";
|
||||
import fetch from "flumm-fetch-cookies";
|
||||
import db from "../src/inc/sql.mjs";
|
||||
import lib from "../src/inc/lib.mjs";
|
||||
import { exec as _exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
const exec = promisify(_exec);
|
||||
//import fetch from "flumm-fetch-cookies";
|
||||
|
||||
const isNSFW = res => {
|
||||
let nsfw = false;
|
||||
if(res.neutral >= .7)
|
||||
nsfw = false;
|
||||
else if((res.sexy + res.porn + res.hentai) >= .7)
|
||||
nsfw = true;
|
||||
else if(res.drawings >= .4)
|
||||
nsfw = false;
|
||||
else
|
||||
nsfw = false;
|
||||
return nsfw;
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const _args = process.argv.slice(2);
|
||||
const _from = +_args[0];
|
||||
const _to = _from + 100;
|
||||
const _to = _from + 0;
|
||||
|
||||
const f0cks = await sql("items")
|
||||
.whereRaw("id not in (select item_id from tags_assign group by item_id)")
|
||||
.andWhere("mime", "like", "image/%")
|
||||
.andWhereBetween("id", [ _from, _to ]);
|
||||
const f0cks = await db`
|
||||
select *
|
||||
from items
|
||||
where
|
||||
id not in (select item_id from tags_assign group by item_id) and
|
||||
mime like 'image/%' and
|
||||
id between ${_from} and ${_to}
|
||||
`;
|
||||
|
||||
const body = { headers: { Authorization: `Basic ${cfg.tagger.btoa}` } };
|
||||
|
||||
console.time('blah');
|
||||
for(let f of f0cks) {
|
||||
let tag;
|
||||
const res = await (await fetch(`${cfg.tagger.endpoint}/categories/nsfw_beta?image_url=${cfg.main.url}/b/${f.dest}`, body)).json();
|
||||
if(res?.result) {
|
||||
tag = (res.result.categories[0].name.en === "safe") ? "sfw" : "nsfw";
|
||||
const tmp = await lib.detectNSFW(f.dest);
|
||||
|
||||
await sql("tags_assign").insert({
|
||||
tag_id: tag === "sfw" ? 1 : 2,
|
||||
item_id: f.id,
|
||||
user_id: 7 // user: autotagger
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log(res);
|
||||
console.log(
|
||||
'https://f0ck.me/' + f.id,
|
||||
tmp.isNSFW,
|
||||
tmp.score.toFixed(2),
|
||||
{
|
||||
sexy: tmp.scores.sexy.toFixed(2),
|
||||
porn: tmp.scores.porn.toFixed(2),
|
||||
hentai: tmp.scores.hentai.toFixed(2),
|
||||
neutral: tmp.scores.neutral.toFixed(2)
|
||||
}
|
||||
);
|
||||
|
||||
await db`
|
||||
insert into "tags_assign" ${
|
||||
db({
|
||||
item_id: f.id,
|
||||
tag_id: tmp.nsfw ? 2 : 1,
|
||||
user_id: 7
|
||||
})
|
||||
}
|
||||
`;
|
||||
|
||||
if(tmp.hentai >= .7) {
|
||||
await db`
|
||||
insert into "tags_assign" ${
|
||||
db({
|
||||
item_id: f.id,
|
||||
tag_id: 8, // hentai
|
||||
user_id: 7 // autotagger
|
||||
})
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
console.timeEnd('blah');
|
||||
process.exit();
|
||||
})();
|
||||
|
Reference in New Issue
Block a user