new thumbnailer
This commit is contained in:
34
src/lib.js
34
src/lib.js
@ -98,6 +98,38 @@ Lib.prototype.getCheckSum = (file, cbcs) => {
|
||||
});
|
||||
};
|
||||
Lib.prototype.generateThumbs = () => {
|
||||
var outdir = './t';
|
||||
Lib.prototype.sql.query("select * from `f0ck`.`items`", (err, rows, fields) => {
|
||||
rows.forEach((e,i,a) => {
|
||||
var thumbnail = outdir+'/'+e.id+'.png';
|
||||
if(!fs.existsSync(thumbnail)) {
|
||||
var cmd;
|
||||
switch(e.mime) {
|
||||
case "video/mp4":
|
||||
case "video/webm":
|
||||
case "audio/mpeg":
|
||||
case "audio/ogg":
|
||||
case "image/gif":
|
||||
cmd = 'ffmpeg -i '+e.dest+' -vframes 1 -filter "scale=-1:256,crop=128:128" '+thumbnail;
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/jpeg":
|
||||
cmd = 'convert -thumbnail 256x256 '+e.dest+' -gravity center -crop 128x128+0+0 +repage '+thumbnail;
|
||||
break;
|
||||
}
|
||||
exec(cmd, (error) => {
|
||||
if(error) {
|
||||
Lib.prototype.log('failed thumbnail for '+e.id+' ('+e.mime+') '+JSON.stringify(error));
|
||||
fs.copySync('./s/mp3.png', thumbnail); // copy standardthumbnail
|
||||
}
|
||||
else
|
||||
Lib.prototype.log("generated thumbnail for "+e.id+" ("+e.mime+")");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/*Lib.prototype.generateThumbs = () => {
|
||||
var outdir = './t/';
|
||||
Lib.prototype.sql.query("select * from `f0ck`.`items`", (err, rows, fields) => {
|
||||
rows.forEach((e,i,a) => {
|
||||
@ -120,7 +152,7 @@ Lib.prototype.generateThumbs = () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
};*/
|
||||
Lib.prototype.log = (msg) => {
|
||||
if(Lib.prototype.debug)
|
||||
bot.send(Lib.prototype.cfg.debugchannel, msg, 'n0xy');
|
||||
|
@ -3,19 +3,25 @@
|
||||
module.exports = (bot, lib) => {
|
||||
lib.trigger.add({
|
||||
name: 'thumbnailer',
|
||||
call: /^\!thumb (\d+)$/i,
|
||||
call: /^\!thumb(.*\d+)?$/i,
|
||||
level: 100,
|
||||
active: 1,
|
||||
func: (e) => {
|
||||
var id = e.message.split(' ')[1];
|
||||
if(Number.isInteger(parseInt(id))) {
|
||||
fs.unlink('./t/'+id+'.png', () => {
|
||||
//e.reply('debug: Thumbnail gelöscht');
|
||||
lib.generateThumbs();
|
||||
//e.reply('debug: sollte Thumbnail generiert haben');
|
||||
});
|
||||
var id;
|
||||
if(id = e.message.split(' ')[1]) {
|
||||
if(Number.isInteger(parseInt(id)))
|
||||
fs.unlink('./t/'+id+'.png', () => lib.generateThumbs() );
|
||||
}
|
||||
else {
|
||||
deleteFolderRecursive('./t');
|
||||
lib.generateThumbs();
|
||||
}
|
||||
},
|
||||
desc: 'regenerate thumbnail'
|
||||
desc: 'generate thumbnail'
|
||||
});
|
||||
};
|
||||
|
||||
var deleteFolderRecursive = (path) => {
|
||||
if(fs.existsSync(path))
|
||||
fs.readdirSync(path).forEach((file,index) => (fs.lstatSync(path+"/"+file).isDirectory())?deleteFolderRecursive(path+"/"+file):fs.unlinkSync(path+"/"+file) );
|
||||
};
|
Reference in New Issue
Block a user