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,10 +18,12 @@ 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) {
ytdl.getInfo(entry, (err, info) => {
var title = info.title;
var dat = fs.createWriteStream('./b/'+tmpdest+'.webm'); var dat = fs.createWriteStream('./b/'+tmpdest+'.webm');
//ytdl(entry)
try { try {
ytdl(entry, { filter: (format) => { return format.container === 'webm'; } }) ytdl.downloadFromInfo(info, { filter: (format) => { return format.container === 'webm'; } })
.on('response', (res) => { .on('response', (res) => {
if(res.headers['content-length'] > lib.cfg.maxFileSize) { if(res.headers['content-length'] > lib.cfg.maxFileSize) {
res.destroy(); res.destroy();
@ -36,13 +38,11 @@ module.exports = (bot, trigger, lib) => {
} }
catch(ex) { catch(ex) {
e.reply(ex); e.reply(ex);
dl = false;
} }
dat.on('finish', () => { dat.on('finish', () => {
if(dl) { if(dl) {
dat.close(); dat.close();
//probe("./b/"+tmpdest+".webm", (err, probeData) => {
// var size = probeData.size;
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) => {
@ -61,7 +61,7 @@ module.exports = (bot, trigger, lib) => {
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);
}); });
@ -73,11 +73,11 @@ module.exports = (bot, trigger, lib) => {
}); });
}); });
}); });
//});
} }
else else
fs.unlink('./b/'+tmpdest+'.webm'); fs.unlink('./b/'+tmpdest+'.webm');
}); });
});
} }
else else
e.reply('repost motherf0cker'); e.reply('repost motherf0cker');