Fix midify
This commit is contained in:
parent
66c0367265
commit
b0b663b8d0
1 changed files with 15 additions and 11 deletions
|
@ -5,6 +5,8 @@ const youtubedl = require('youtube-dl');
|
|||
const os = require('os');
|
||||
const filetype = require('file-type');
|
||||
const fs = require('fs');
|
||||
const ffmpeg = require('fluent-ffmpeg');
|
||||
|
||||
|
||||
class midifyCommand extends Command {
|
||||
constructor() {
|
||||
|
@ -57,27 +59,29 @@ class midifyCommand extends Command {
|
|||
}
|
||||
let ext = 'mp4';
|
||||
|
||||
if (fs.existsSync(`${os.tmpdir()}/${input}`)) {
|
||||
ext = await filetype.fromFile(`${os.tmpdir()}/${input}`);
|
||||
if (fs.existsSync(input)) {
|
||||
ext = await filetype.fromFile(input);
|
||||
ext = ext.ext; // This look stupid but hey, it work
|
||||
if (ext == '3gp') ext = 'mp4'; // Change 3gp file extension to mp4 so discord show the video ( and to stop people from complaining )
|
||||
fs.renameSync(`${os.tmpdir()}/${input}`, `${os.tmpdir()}/${input}.${ext}`);
|
||||
} else if (fs.existsSync(`${os.tmpdir()}/${input}.mkv`)) { // If it can't find the video assume it got merged and end with mkv
|
||||
fs.renameSync(`${os.tmpdir()}/${input}.mkv`, `${os.tmpdir()}/${input}.mp4`); // Discord play mkv just fine but it need to end with mp4
|
||||
fs.renameSync(input, `${input}.${ext}`);
|
||||
} else if (fs.existsSync(`${input}.mkv`)) { // If it can't find the video assume it got merged and end with mkv
|
||||
fs.renameSync(`${input}.mkv`, `${input}.mp4`); // Discord play mkv just fine but it need to end with mp4
|
||||
}
|
||||
|
||||
input = `${os.tmpdir()}/${message.id}.${ext}`;
|
||||
|
||||
// Convert to wav
|
||||
exec(`ffmpeg -i ${input} ${input2}`)
|
||||
.then(() => {
|
||||
ffmpeg()
|
||||
.input(input)
|
||||
.output(input2)
|
||||
.on('end', () => {
|
||||
midify();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
.on('error', (err, stdout, stderr) => {
|
||||
console.error(`${err}\n${stdout}\n${stderr}`);
|
||||
return message.channel.send('Oh no! an error has occured during the conversion, are you sure it is a valid file?');
|
||||
});
|
||||
|
||||
})
|
||||
.run();
|
||||
});
|
||||
} else {
|
||||
return message.channel.send('You need a valid video link!');
|
||||
|
|
Loading…
Reference in a new issue