2016-08-24 07:42:42 +00:00
|
|
|
var fs = require('fs-extra');
|
|
|
|
var ytdl = require('ytdl-core');
|
|
|
|
var uuid = require('uuid');
|
|
|
|
var probe = require('node-ffprobe');
|
|
|
|
|
|
|
|
module.exports = (bot, trigger, lib) => {
|
|
|
|
trigger.add({
|
|
|
|
name: 'ytdl',
|
2016-08-24 20:02:20 +00:00
|
|
|
call: /https?:\/\/(www\.)?(yotu\.be\/|youtube\.com\/)?((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi,
|
2016-08-24 07:42:42 +00:00
|
|
|
level: 0,
|
2016-08-30 21:18:18 +00:00
|
|
|
active: 1,
|
2016-08-24 07:42:42 +00:00
|
|
|
func: (e) => {
|
2016-08-30 21:22:27 +00:00
|
|
|
if(e.channel.getName() == '#f0ck') {
|
2016-08-30 21:18:18 +00:00
|
|
|
if(!e.message.match(/\!ignore/)) {
|
2016-08-24 07:42:42 +00:00
|
|
|
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) => {
|
|
|
|
var dl = true;
|
|
|
|
var tmpdest = uuid.v1().split('-')[0];
|
|
|
|
lib.checkRepost(entry, (cbcr) => {
|
|
|
|
if(cbcr) {
|
|
|
|
var dat = fs.createWriteStream('./b/'+tmpdest+'.webm');
|
2016-08-30 21:18:18 +00:00
|
|
|
//ytdl(entry)
|
|
|
|
try {
|
|
|
|
ytdl(entry, { filter: (format) => { return format.container === 'webm'; } })
|
2016-08-24 07:49:17 +00:00
|
|
|
.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');
|
|
|
|
}
|
|
|
|
})
|
2016-08-24 19:36:18 +00:00
|
|
|
.on('error', (err) => {
|
|
|
|
//e.reply(err);
|
|
|
|
})
|
2016-08-24 07:49:17 +00:00
|
|
|
.pipe( dat );
|
2016-08-30 21:18:18 +00:00
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
e.reply(ex);
|
|
|
|
dl = false;
|
|
|
|
}
|
2016-08-24 07:42:42 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
//});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fs.unlink('./b/'+tmpdest+'.webm');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
e.reply('repost motherf0cker');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
desc: 'download youtubevideos'
|
|
|
|
});
|
|
|
|
};
|