modified: src/trigger/ytdl.js

This commit is contained in:
Flummi 2016-08-30 21:49:47 +00:00
parent 2ca6fefd06
commit 674d28c345

View File

@ -10,7 +10,7 @@ module.exports = (bot, trigger, lib) => {
level: 0, level: 0,
active: 1, active: 1,
func: (e) => { func: (e) => {
if(e.channel.getName() == '#f0ck') { if(e.channel.getName() == '#kbot-dev') {
if(!e.message.match(/\!ignore/)) { if(!e.message.match(/\!ignore/)) {
var tmp = e.message.match(/https?:\/\/(www\.)?(yotu\.be\/|youtube\.com\/)?((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi); // get links var tmp = e.message.match(/https?:\/\/(www\.)?(yotu\.be\/|youtube\.com\/)?((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi); // get links
tmp.forEach((entry,i,a) => { tmp.forEach((entry,i,a) => {
@ -18,65 +18,65 @@ module.exports = (bot, trigger, lib) => {
var tmpdest = uuid.v1().split('-')[0]; var tmpdest = uuid.v1().split('-')[0];
lib.checkRepost(entry, (cbcr) => { lib.checkRepost(entry, (cbcr) => {
if(cbcr) { if(cbcr) {
var dat = fs.createWriteStream('./b/'+tmpdest+'.webm'); ytdl.getInfo(entry, (err, info) => {
//ytdl(entry) var title = info.title;
try { var dat = fs.createWriteStream('./b/'+tmpdest+'.webm');
ytdl(entry, { filter: (format) => { return format.container === 'webm'; } })
.on('response', (res) => { try {
if(res.headers['content-length'] > lib.cfg.maxFileSize) { ytdl.downloadFromInfo(info, { filter: (format) => { return format.container === 'webm'; } })
res.destroy(); .on('response', (res) => {
dl = false; if(res.headers['content-length'] > lib.cfg.maxFileSize) {
e.reply('f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(lib.cfg.maxFileSize)+' allowed'); res.destroy();
} dl = false;
}) e.reply('f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(lib.cfg.maxFileSize)+' allowed');
.on('error', (err) => { }
//e.reply(err); })
}) .on('error', (err) => {
.pipe( dat ); //e.reply(err);
} })
catch(ex) { .pipe( dat );
e.reply(ex); }
dl = false; catch(ex) {
} e.reply(ex);
dat.on('finish', () => { }
if(dl) {
dat.close(); dat.on('finish', () => {
//probe("./b/"+tmpdest+".webm", (err, probeData) => { if(dl) {
// var size = probeData.size; dat.close();
var stat = fs.statSync("./b/"+tmpdest+".webm"); var stat = fs.statSync("./b/"+tmpdest+".webm");
lib.getUser(e, (cbgu) => { lib.getUser(e, (cbgu) => {
lib.getCheckSum("./b/"+tmpdest+".webm", (cbcs) => { lib.getCheckSum("./b/"+tmpdest+".webm", (cbcs) => {
lib.checkRepostCheckSum(cbcs, (cbcrcs) => { lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
if(cbcrcs) { if(cbcrcs) {
lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [ lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [
entry, entry,
"./b/"+tmpdest+".webm", "./b/"+tmpdest+".webm",
"video/webm", "video/webm",
stat.size, stat.size,
cbcs, cbcs,
cbgu['nick'], cbgu['nick'],
e.channel.getName(), e.channel.getName(),
e.network, e.network,
Math.floor(new Date() / 1000), Math.floor(new Date() / 1000),
0 0
]).on('result', (result) => { ]).on('result', (result) => {
lib.generateThumbs(); lib.generateThumbs();
e.reply("https://f0ck.me/"+result.insertId+" - "+entry+" (video/webm, ~"+lib.formatSize(stat.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")"); e.reply("https://f0ck.me/"+result.insertId+" - "+title+" (video/webm, ~"+lib.formatSize(stat.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
}).on('error', (msg) => { }).on('error', (msg) => {
e.reply(msg); e.reply(msg);
}); });
} }
else { else {
fs.unlink("./b/"+tmpdest+".webm"); // delete repost fs.unlink("./b/"+tmpdest+".webm"); // delete repost
e.reply("repost motherf0cker"); e.reply("repost motherf0cker");
} }
});
}); });
}); });
}); }
//}); else
} fs.unlink('./b/'+tmpdest+'.webm');
else });
fs.unlink('./b/'+tmpdest+'.webm');
}); });
} }
else else