diff --git a/.gitignore b/.gitignore index a24f2cdd..7f908eca 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,8 @@ json/uncensor.json # other dectalk/ unloaded.js +asset/ytp/userVid/*.mp4 +asset/ytp/music/ +asset/ytp/resources/ +asset/ytp/sounds/ +asset/ytp/sources/ \ No newline at end of file diff --git a/asset/ytp/outro.mp4 b/asset/ytp/outro.mp4 new file mode 100644 index 00000000..277d744d Binary files /dev/null and b/asset/ytp/outro.mp4 differ diff --git a/asset/ytp/userVid/Video for ytp command goes here b/asset/ytp/userVid/Video for ytp command goes here new file mode 100644 index 00000000..e69de29b diff --git a/commands/fun/ytp.js b/commands/fun/ytp.js new file mode 100644 index 00000000..cef92184 --- /dev/null +++ b/commands/fun/ytp.js @@ -0,0 +1,109 @@ +const { Command } = require('discord-akairo'); +const YTPGenerator = require('ytpplus-node'); +const os = require('os'); +const fs = require('fs'); +const youtubedl = require('youtube-dl'); + +class ytpCommand extends Command { + constructor() { + super('ytp', { + aliases: ['ytp', 'ytpplus', 'ytp+'], + category: 'fun', + args: [ + { + id: 'add', + match: 'flag', + flag: ['--add'] + }, + { + id: 'link', + type: 'string' + } + ], + description: { + content: 'Generate random ytp (--add with a link or attachment to add a video to the pool, only .mp4 work)', + usage: '', + examples: [''] + } + }); + } + + async exec(message, args) { + if (!message.channel.nsfw) return message.channel.send('Please execute this command in an NSFW channel ( Content might not be NSFW but since the video are user submitted better safe than sorry )'); + if (args.add) { + let loadingmsg = await message.channel.send('Downloading '); + let Attachment = (message.attachments).array(); + let url = args.link; + // Get attachment link + if (Attachment[0] && !args.link) { + url = Attachment[0].url; + } + + if (url) { + return youtubedl.exec(url, ['-o', `./asset/ytp/userVid/${message.id}.mp4`], {}, function(err) { + if (err) { + console.error(err); + loadingmsg.delete(); + return message.channel.send('An error has occured, I can\'t download from the link you provided.'); + } else { + return message.channel.send('Video sucessfully added to the pool!'); + } + }); + } else { + return message.channel.send('You need a valid video link!'); + } + } + + let loadingmsg = await message.channel.send('Processing, this can take a long time '); + + // Read userVid folder and only take .mp4 + let asset = []; + fs.readdir('./asset/ytp/userVid/', (err, files) => { + files.forEach(file => { + if (file.endsWith('.mp4')) { + asset.push(`./asset/ytp/userVid/${file}`); + } + }); + + let options = { + debug: false, // Better set this to false to avoid flood in console + MIN_STREAM_DURATION: Math.floor((Math.random() * 2) + 1), // Random duration of video clip + sources: './asset/ytp/sources/', + sounds: './asset/ytp/sounds/', + music: './asset/ytp/music/', + resources: './asset/ytp/resources/', + temp: os.tmpdir(), + sourceList: asset, + outro: './asset/ytp/outro.mp4', // Need an outro or it won't work + OUTPUT_FILE: `${os.tmpdir()}/${message.id}_YTP.mp4`, + MAX_CLIPS: 20, + transitions: true, + effects: { + effect_RandomSound: true, + effect_RandomSoundMute: true, + effect_Reverse: true, + effect_Chorus: true, + effect_Vibrato: true, + effect_HighPitch: true, + effect_LowPitch: true, + effect_SpeedUp: true, + effect_SlowDown: true, + effect_Dance: true, + effect_Squidward: false + } + }; + + new YTPGenerator().configurateAndGo(options) + .then(() => { + loadingmsg.delete(); + return message.reply('Here is your YTP!', {files: [`${os.tmpdir()}/${message.id}_YTP.mp4`]}); + }) + .catch(() => { + loadingmsg.delete(); + return message.reply('Oh no! An error has occured!'); + }); + }); + } +} + +module.exports = ytpCommand; \ No newline at end of file