lekker thumbnailer jongen
This commit is contained in:
parent
da6b310449
commit
081df808d9
73
debug/thumbnailer.mjs
Normal file
73
debug/thumbnailer.mjs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import cfg from "../src/inc/config.mjs";
|
||||||
|
import sql from "../src/inc/sql.mjs";
|
||||||
|
import { promises as fs } from "fs";
|
||||||
|
import { exec as _exec } from "child_process";
|
||||||
|
import fetch from "flumm-fetch-cookies";
|
||||||
|
|
||||||
|
const exec = cmd => new Promise((resolve, reject) => {
|
||||||
|
_exec(cmd, { maxBuffer: 5e3 * 1024 }, (err, stdout, stderr) => {
|
||||||
|
if(err)
|
||||||
|
return reject(err);
|
||||||
|
if(stderr)
|
||||||
|
console.error(stderr);
|
||||||
|
resolve({ stdout: stdout });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const _args = process.argv.slice(2);
|
||||||
|
const _itemid = +_args[0] || 1;
|
||||||
|
|
||||||
|
const items = await sql('items').where('id', _itemid);//.where('mime', 'like', 'audio/%');
|
||||||
|
let count = 1;
|
||||||
|
let total = items.length;
|
||||||
|
|
||||||
|
for(let item of items) {
|
||||||
|
const itemid = item.id;
|
||||||
|
const filename = item.dest;
|
||||||
|
const mime = item.mime;
|
||||||
|
try {
|
||||||
|
if(mime.startsWith('video/') || mime == 'image/gif')
|
||||||
|
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${itemid}.png`);
|
||||||
|
else if(mime.startsWith('image/') && mime != 'image/gif')
|
||||||
|
await exec(`convert ./public/b/${filename} ./tmp/${itemid}.png`);
|
||||||
|
else if(mime.startsWith('audio/')) {
|
||||||
|
if(item.src.match(/soundcloud/)) {
|
||||||
|
const cover = (await exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' --get-thumbnail "${item.src}"`)).stdout.trim();
|
||||||
|
if(!cover.match(/default_avatar/)) {
|
||||||
|
try {
|
||||||
|
await exec(`wget "${cover}" -O ./tmp/${itemid}.jpg`);
|
||||||
|
const size = (await fs.stat(`./tmp/${itemid}.jpg`)).size;
|
||||||
|
if(size >= 0)
|
||||||
|
await exec(`convert ./tmp/${itemid}.jpg ./tmp/${itemid}.png`);
|
||||||
|
await fs.unlink(`./tmp/${itemid}.jpg`);
|
||||||
|
} catch(err) {}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${itemid}.png`);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${itemid}.png`);
|
||||||
|
await fs.copyFile(`./tmp/${itemid}.png`, `./public/ca/${itemid}.png`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await exec(`convert "./tmp/${itemid}.png" -resize "128x128^" -gravity center -crop 128x128+0+0 +repage ./public/t/${itemid}.png`);
|
||||||
|
await fs.unlink(`./tmp/${itemid}.png`);
|
||||||
|
|
||||||
|
} catch(err) {
|
||||||
|
await fs.copyFile('./mugge.png', `./public/t/${itemid}.png`);
|
||||||
|
}
|
||||||
|
console.log(`current: ${itemid} (${count} / ${total})`);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*for(let item of items) {
|
||||||
|
try {
|
||||||
|
const itemid = item.id;
|
||||||
|
const filename = item.dest;
|
||||||
|
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./debug/tmp/${itemid}`);
|
||||||
|
await exec(`convert "./debug/tmp/${itemid}" -resize "128x128^" -gravity center -crop 128x128+0+0 +repage ./public/t/${itemid}.png`);
|
||||||
|
await fs.unlink(`./debug/tmp/${itemid}`);
|
||||||
|
console.log(`current: ${itemid} (${count} / ${total})`);
|
||||||
|
} catch(err) {}
|
||||||
|
count++;
|
||||||
|
};*/
|
|
@ -7,6 +7,8 @@
|
||||||
"start": "node --experimental-json-modules src/index.mjs",
|
"start": "node --experimental-json-modules src/index.mjs",
|
||||||
"trigger": "node --experimental-json-modules debug/trigger.mjs",
|
"trigger": "node --experimental-json-modules debug/trigger.mjs",
|
||||||
"autotagger": "node --experimental-json-modules debug/autotagger.mjs",
|
"autotagger": "node --experimental-json-modules debug/autotagger.mjs",
|
||||||
|
"thumbnailer": "node --experimental-json-modules debug/thumbnailer.mjs",
|
||||||
|
"test": "node --experimental-json-modules debug/test.mjs",
|
||||||
"clean": "node --experimental-json-modules debug/clean.mjs"
|
"clean": "node --experimental-json-modules debug/clean.mjs"
|
||||||
},
|
},
|
||||||
"author": "Flummi",
|
"author": "Flummi",
|
||||||
|
|
|
@ -127,52 +127,70 @@ export default async bot => {
|
||||||
stamp: ~~(new Date() / 1000),
|
stamp: ~~(new Date() / 1000),
|
||||||
active: 1
|
active: 1
|
||||||
});
|
});
|
||||||
const insertq = (await sql('items').where('dest', filename).limit(1))[0].id;
|
const itemid = (await sql('items').where('dest', filename).limit(1))[0].id;
|
||||||
|
|
||||||
// generate thumbnail
|
// generate thumbnail
|
||||||
try {
|
try {
|
||||||
let thumb_orig = (await exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' --get-thumbnail "${link}"`)).stdout.trim();
|
if(mime.startsWith('video/') || mime == 'image/gif')
|
||||||
if(!thumb_orig.startsWith("http")) {
|
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${itemid}.png`);
|
||||||
if(mime.startsWith("image") && mime !== "image/gif")
|
else if(mime.startsWith('image/') && mime != 'image/gif')
|
||||||
thumb_orig = `./public/b/${filename}`;
|
await exec(`convert ./public/b/${filename} ./tmp/${itemid}.png`);
|
||||||
else if(!mime.startsWith("audio")) {
|
else if(mime.startsWith('audio/')) {
|
||||||
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${insertq}`);
|
if(link.match(/soundcloud/)) {
|
||||||
thumb_orig = `./tmp/${insertq}`;
|
const cover = (await exec(`yt-dlp -f 'bv*[height<=720]+ba/b[height<=720] / wv*+ba/w' --get-thumbnail "${link}"`)).stdout.trim();
|
||||||
}
|
if(!cover.match(/default_avatar/)) {
|
||||||
else if(mime.startsWith("audio")) {
|
try {
|
||||||
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${insertq}.png`)
|
await exec(`wget "${cover}" -O ./tmp/${itemid}.jpg`);
|
||||||
await exec(`cp ./tmp/${insertq}.png ./public/ca/${insertq}.png`)
|
const size = (await fs.promises.stat(`./tmp/${itemid}.jpg`)).size;
|
||||||
thumb_orig = `./tmp/${insertq}.png`;
|
if(size >= 0)
|
||||||
|
await exec(`convert ./tmp/${itemid}.jpg ./tmp/${itemid}.png`);
|
||||||
|
await fs.promises.unlink(`./tmp/${itemid}.jpg`);
|
||||||
|
} catch(err) {}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${itemid}.png`);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${itemid}.png`);
|
||||||
|
await fs.promises.copyFile(`./tmp/${itemid}.png`, `./public/ca/${itemid}.png`);
|
||||||
}
|
}
|
||||||
await exec(`convert "${thumb_orig}" -resize "128x128^" -gravity center -crop 128x128+0+0 +repage ./public/t/${insertq}.png`);
|
|
||||||
await fs.promises.unlink(`./tmp/${insertq}`).catch(_=>{});
|
await exec(`convert "./tmp/${itemid}.png" -resize "128x128^" -gravity center -crop 128x128+0+0 +repage ./public/t/${itemid}.png`);
|
||||||
|
await fs.promises.unlink(`./tmp/${itemid}.png`);
|
||||||
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
e.reply("\x033>no thumb lol");
|
await fs.promises.copyFile('./mugge.png', `./public/t/${itemid}.png`);
|
||||||
console.error(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let speed = lib.calcSpeed(size, end);
|
let speed = lib.calcSpeed(size, end);
|
||||||
speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`;
|
speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`;
|
||||||
|
|
||||||
// tagger
|
// autotagger
|
||||||
let tag;
|
let tag;
|
||||||
if(mime.startsWith("image")) {
|
try {
|
||||||
const body = { headers: { Authorization: `Basic ${cfg.tagger.btoa}` } };
|
if(mime.startsWith('image') && mime != 'image/gif') {
|
||||||
const res = await (await fetch(`${cfg.tagger.endpoint}/categories/nsfw_beta?image_url=${cfg.main.url}/b/${filename}`, body)).json();
|
const body = { headers: { Authorization: `Basic ${cfg.tagger.btoa}` } };
|
||||||
if(res) {
|
const res = await (await fetch(`${cfg.tagger.endpoint}/categories/nsfw_beta?image_url=${cfg.main.url}/b/${filename}`, body)).json();
|
||||||
tag = (res.result.categories[0].name.en === "safe") ? "sfw" : "nsfw";
|
if(res)
|
||||||
|
tag = (res.result.categories[0].name.en === 'safe') ? 'sfw' : 'nsfw';
|
||||||
|
}
|
||||||
|
else if(mime.startsWith('audio')) {
|
||||||
|
tag = 'sfw';
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tag === 'sfw' || tag === 'nsfw') {
|
||||||
await sql("tags_assign").insert({
|
await sql("tags_assign").insert({
|
||||||
tag_id: tag === "sfw" ? 1 : 2,
|
tag_id: tag === "sfw" ? 1 : 2,
|
||||||
item_id: insertq,
|
item_id: itemid,
|
||||||
user_id: 7 // user: autotagger
|
user_id: 7 // user: autotagger (ID: 7)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch(err) {
|
||||||
|
console.error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
e.reply([
|
e.reply([
|
||||||
`[f0cked] link: ${cfg.main.url}/${insertq} | size: ${lib.formatSize(size)} | speed: ${speed}` + (tag ? ` | ${tag}` : "")
|
`[f0cked] link: ${cfg.main.url}/${itemid} | size: ${lib.formatSize(size)} | speed: ${speed}` + (tag ? ` | ${tag}` : "")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user