+ytdl-trigger
This commit is contained in:
parent
7cf82cb7f7
commit
dc3cf38670
|
@ -9,10 +9,11 @@
|
|||
"coffea": "^0.4.24",
|
||||
"fs-extra": "^0.30.0",
|
||||
"mysql": "^2.11.1",
|
||||
"node-ffprobe": "^1.2.2",
|
||||
"repl": "^0.1.3",
|
||||
"swig": "^1.4.2",
|
||||
"uuid": "^2.0.2",
|
||||
"node-ffprobe": "^1.2.2"
|
||||
"ytdl-core": "^0.7.17"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
80
src/trigger/ytdl.js
Normal file
80
src/trigger/ytdl.js
Normal file
|
@ -0,0 +1,80 @@
|
|||
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',
|
||||
call: new RegExp('(https?://)?(www\\.)?(yotu\\.be/|youtube\\.com/)?((.+/)?(watch(\\?v=|.+&v=))?(v=)?)([\\w_-]{11})(&.+)?', 'gi'),
|
||||
level: 0,
|
||||
func: (e) => {
|
||||
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) => {
|
||||
var dl = true;
|
||||
var tmpdest = uuid.v1().split('-')[0];
|
||||
lib.checkRepost(entry, (cbcr) => {
|
||||
if(cbcr) {
|
||||
var dat = fs.createWriteStream('./b/'+tmpdest+'.webm');
|
||||
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');
|
||||
}
|
||||
})
|
||||
.pipe( dat );
|
||||
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'
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user