From 674d28c345b78376c6886aa0e5a3705504f8f1ad Mon Sep 17 00:00:00 2001 From: Flummi Date: Tue, 30 Aug 2016 21:49:47 +0000 Subject: [PATCH] modified: src/trigger/ytdl.js --- src/trigger/ytdl.js | 116 ++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/trigger/ytdl.js b/src/trigger/ytdl.js index d6ac5e6..62cb7f7 100644 --- a/src/trigger/ytdl.js +++ b/src/trigger/ytdl.js @@ -10,7 +10,7 @@ module.exports = (bot, trigger, lib) => { level: 0, active: 1, func: (e) => { - if(e.channel.getName() == '#f0ck') { + if(e.channel.getName() == '#kbot-dev') { 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 tmp.forEach((entry,i,a) => { @@ -18,65 +18,65 @@ module.exports = (bot, trigger, lib) => { var tmpdest = uuid.v1().split('-')[0]; lib.checkRepost(entry, (cbcr) => { if(cbcr) { - var dat = fs.createWriteStream('./b/'+tmpdest+'.webm'); - //ytdl(entry) - try { - ytdl(entry, { filter: (format) => { return format.container === 'webm'; } }) - .on('response', (res) => { - if(res.headers['content-length'] > lib.cfg.maxFileSize) { - 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); - }) - .pipe( dat ); - } - catch(ex) { - e.reply(ex); - dl = false; - } - dat.on('finish', () => { - if(dl) { - dat.close(); - //probe("./b/"+tmpdest+".webm", (err, probeData) => { - // var size = probeData.size; - var stat = fs.statSync("./b/"+tmpdest+".webm"); - lib.getUser(e, (cbgu) => { - lib.getCheckSum("./b/"+tmpdest+".webm", (cbcs) => { - lib.checkRepostCheckSum(cbcs, (cbcrcs) => { - if(cbcrcs) { - lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [ - entry, - "./b/"+tmpdest+".webm", - "video/webm", - stat.size, - cbcs, - cbgu['nick'], - e.channel.getName(), - e.network, - Math.floor(new Date() / 1000), - 0 - ]).on('result', (result) => { - lib.generateThumbs(); - e.reply("https://f0ck.me/"+result.insertId+" - "+entry+" (video/webm, ~"+lib.formatSize(stat.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")"); - }).on('error', (msg) => { - e.reply(msg); - }); - } - else { - fs.unlink("./b/"+tmpdest+".webm"); // delete repost - e.reply("repost motherf0cker"); - } + ytdl.getInfo(entry, (err, info) => { + var title = info.title; + var dat = fs.createWriteStream('./b/'+tmpdest+'.webm'); + + try { + ytdl.downloadFromInfo(info, { filter: (format) => { return format.container === 'webm'; } }) + .on('response', (res) => { + if(res.headers['content-length'] > lib.cfg.maxFileSize) { + 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); + }) + .pipe( dat ); + } + catch(ex) { + e.reply(ex); + } + + dat.on('finish', () => { + if(dl) { + dat.close(); + var stat = fs.statSync("./b/"+tmpdest+".webm"); + lib.getUser(e, (cbgu) => { + lib.getCheckSum("./b/"+tmpdest+".webm", (cbcs) => { + lib.checkRepostCheckSum(cbcs, (cbcrcs) => { + if(cbcrcs) { + lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [ + entry, + "./b/"+tmpdest+".webm", + "video/webm", + stat.size, + cbcs, + cbgu['nick'], + e.channel.getName(), + e.network, + Math.floor(new Date() / 1000), + 0 + ]).on('result', (result) => { + lib.generateThumbs(); + e.reply("https://f0ck.me/"+result.insertId+" - "+title+" (video/webm, ~"+lib.formatSize(stat.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")"); + }).on('error', (msg) => { + e.reply(msg); + }); + } + else { + fs.unlink("./b/"+tmpdest+".webm"); // delete repost + e.reply("repost motherf0cker"); + } + }); }); }); - }); - //}); - } - else - fs.unlink('./b/'+tmpdest+'.webm'); + } + else + fs.unlink('./b/'+tmpdest+'.webm'); + }); }); } else