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