Compare commits
No commits in common. "aacd7aa9facb240dcaa91dd54093af10a2a55c87" and "d4e3693be659409f015946054350e32549273829" have entirely different histories.
aacd7aa9fa
...
d4e3693be6
5 changed files with 14 additions and 50 deletions
|
@ -41,7 +41,7 @@ export default {
|
|||
const file = fs.statSync(`${os.tmpdir()}/${args.audio.name}.png`);
|
||||
const fileSize = (file.size / 1000000.0).toFixed(2);
|
||||
|
||||
if (fileSize > await utils.getMaxFileSize(interaction.guild)) return interaction.editReply('error');
|
||||
if (fileSize > utils.getMaxFileSize(interaction.guild)) return interaction.editReply('error');
|
||||
interaction.editReply({ content: `Image file is ${fileSize} MB` });
|
||||
return interaction.followUp({ files: [`${os.tmpdir()}/${args.audio.name}.png`] });
|
||||
},
|
||||
|
|
|
@ -40,7 +40,7 @@ export default {
|
|||
const file = fs.statSync(`${os.tmpdir()}/${args.img.name}.mp3`);
|
||||
const fileSize = (file.size / 1000000.0).toFixed(2);
|
||||
|
||||
if (fileSize > await utils.getMaxFileSize(interaction.guild)) return interaction.editReply('error');
|
||||
if (fileSize > utils.getMaxFileSize(interaction.guild)) return interaction.editReply('error');
|
||||
interaction.editReply({ content: `Audio file is ${fileSize} MB` });
|
||||
return interaction.followUp({ files: [`${os.tmpdir()}/${args.img.name}.mp3`] });
|
||||
},
|
||||
|
|
|
@ -6,7 +6,6 @@ import utils from '../../utils/videos.js';
|
|||
|
||||
let client;
|
||||
let cleanUp;
|
||||
let maxFileSize;
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -31,9 +30,7 @@ export default {
|
|||
client = c;
|
||||
const url = args.url;
|
||||
const format = args.format;
|
||||
maxFileSize = await utils.getMaxFileSize(interaction.guild);
|
||||
interaction.doCompress = args.compress;
|
||||
|
||||
if (interaction.cleanUp) {
|
||||
cleanUp = interaction.cleanUp;
|
||||
}
|
||||
|
@ -49,15 +46,6 @@ export default {
|
|||
return interaction.editReply({ content: '❌ This does not look like a valid url!', ephemeral: true });
|
||||
}
|
||||
|
||||
const aproxFileSize = await utils.getVideoSize(url, format);
|
||||
|
||||
if (aproxFileSize > 100 && !args.compress) {
|
||||
await interaction.followUp('Uh oh! The video you tried to download is larger than 100 mb! Try again with compression.', { ephemeral: true });
|
||||
}
|
||||
else if (aproxFileSize > 500) {
|
||||
await interaction.followUp('Uh oh! The video you tried to download is larger than 500 mb!', { ephemeral: true });
|
||||
}
|
||||
|
||||
if (format) {
|
||||
let qualitys = await new Promise((resolve, reject) => {
|
||||
exec(`./bin/yt-dlp "${url}" --print "%()j"`, (err, stdout, stderr) => {
|
||||
|
@ -128,13 +116,11 @@ export default {
|
|||
|
||||
async function download(url, interaction, originalInteraction) {
|
||||
let format = 'bestvideo*+bestaudio/best';
|
||||
|
||||
const Embed = new EmbedBuilder()
|
||||
.setColor(interaction.member ? interaction.member.displayHexColor : 'Navy')
|
||||
.setAuthor({ name: `Downloaded by ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL(), url: url })
|
||||
.setFooter({ text: `You can get the original video by clicking on the "Downloaded by ${interaction.user.tag}" message!` });
|
||||
|
||||
|
||||
if (interaction.customId === `downloadQuality${interaction.user.id}`) {
|
||||
format = interaction.values[0];
|
||||
if (interaction.values[1]) format += '+' + interaction.values[1];
|
||||
|
@ -145,6 +131,8 @@ async function download(url, interaction, originalInteraction) {
|
|||
const file = fs.readdirSync(os.tmpdir()).filter(fn => fn.startsWith(interaction.id));
|
||||
let output = `${os.tmpdir()}/${file}`;
|
||||
|
||||
const fileStat = fs.statSync(output);
|
||||
const fileSize = fileStat.size / 1000000.0;
|
||||
const compressInteraction = originalInteraction ? originalInteraction : interaction;
|
||||
if (compressInteraction.doCompress) {
|
||||
const presets = [ 'Social 8 MB 3 Minutes 360p30', 'Social 50 MB 10 Minutes 480p30', 'Social 50 MB 5 Minutes 720p30', 'Social 100 MB 5 Minutes 1080p30' ];
|
||||
|
@ -184,27 +172,22 @@ async function download(url, interaction, originalInteraction) {
|
|||
const codec = await utils.getVideoCodec(output);
|
||||
|
||||
if (bannedFormats.includes(codec)) {
|
||||
console.log('Reencoding video');
|
||||
const oldOutput = output;
|
||||
output = `${os.tmpdir()}/264${file}`;
|
||||
await utils.ffmpeg(`-i ${oldOutput} -vcodec libx264 -acodec aac ${output}`);
|
||||
}
|
||||
|
||||
const fileStat = fs.statSync(output);
|
||||
const fileSize = fileStat.size / 1000000.0;
|
||||
|
||||
Embed.setAuthor({ name: `${Embed.data.author.name} (${fileSize.toFixed(2)} MB)`, iconURL: Embed.data.author.icon_url, url: Embed.data.author.url });
|
||||
|
||||
|
||||
if (fileSize > 100) {
|
||||
await interaction.deleteReply();
|
||||
await interaction.followUp('Uh oh! The video you tried to download is too big!', { ephemeral: true });
|
||||
}
|
||||
else if (fileSize > maxFileSize) {
|
||||
else if (fileSize > utils.getMaxFileSize(interaction.guild)) {
|
||||
const fileurl = await utils.upload(output)
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
await interaction.editReply({ content: `File was bigger than ${maxFileSize} mb. It has been uploaded to an external site.`, embeds: [Embed], ephemeral: false });
|
||||
await interaction.editReply({ content: 'File was bigger than 8 mb. It has been uploaded to an external site.', embeds: [Embed], ephemeral: false });
|
||||
await interaction.followUp({ content: fileurl, ephemeral: false });
|
||||
}
|
||||
else {
|
||||
|
@ -223,19 +206,14 @@ async function download(url, interaction, originalInteraction) {
|
|||
async function compress(input, interaction, embed) {
|
||||
const output = `compressed${input}.mp4`;
|
||||
// Delete the file as it apparently don't overwrite?
|
||||
if (fs.existsSync(output)) {
|
||||
fs.rmSync(output);
|
||||
}
|
||||
|
||||
fs.rmSync(output);
|
||||
utils.compressVideo(`${os.tmpdir()}/${input}`, output, interaction.values[0])
|
||||
.then(async () => {
|
||||
const fileStat = fs.statSync(`${os.tmpdir()}/${output}`);
|
||||
const fileSize = fileStat.size / 1000000.0;
|
||||
|
||||
embed.setAuthor({ name: `${embed.data.author.name} (${fileSize.toFixed(2)} MB)`, iconURL: embed.data.author.icon_url, url: embed.data.author.url });
|
||||
|
||||
if (fileSize > maxFileSize) {
|
||||
await interaction.editReply({ content: `File was bigger than ${maxFileSize} mb. It has been uploaded to an external site.`, ephemeral: false });
|
||||
if (fileSize > utils.getMaxFileSize(interaction.guild)) {
|
||||
await interaction.editReply({ content: 'File was bigger than 8 mb. but due to the compression it is not being uploaded externally.', ephemeral: true });
|
||||
}
|
||||
else {
|
||||
await interaction.editReply({ embeds: [embed], files: [`${os.tmpdir()}/${output}`], ephemeral: false });
|
||||
|
|
|
@ -46,7 +46,7 @@ export default {
|
|||
await interaction.deleteReply();
|
||||
await interaction.followUp('❌ Uh oh! The video once converted is too big!', { ephemeral: true });
|
||||
}
|
||||
else if (fileSize > await utils.getMaxFileSize(interaction.guild)) {
|
||||
else if (fileSize > utils.getMaxFileSize(interaction.guild)) {
|
||||
const fileURL = await utils.upload(gifsicleOutput)
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
|
|
|
@ -9,7 +9,6 @@ export default {
|
|||
stringIsAValidurl,
|
||||
compressVideo,
|
||||
getVideoCodec,
|
||||
getVideoSize,
|
||||
getMaxFileSize,
|
||||
};
|
||||
async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') {
|
||||
|
@ -94,23 +93,10 @@ async function getVideoCodec(input) {
|
|||
});
|
||||
}
|
||||
|
||||
async function getVideoSize(urlArg, format = 'bestvideo*+bestaudio/best') {
|
||||
return await new Promise((resolve, reject) => {
|
||||
exec(`yt-dlp ${urlArg} -f ${format} -O "%(filesize,filesize_approx)s"`, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(stderr);
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(stderr);
|
||||
}
|
||||
resolve(stdout / 1000000.0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function getMaxFileSize(guild) {
|
||||
return await new Promise((resolve) => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
const tier = guild.premiumTier;
|
||||
console.log(tier);
|
||||
switch (tier) {
|
||||
case 0:
|
||||
case 1:
|
||||
|
@ -123,7 +109,7 @@ async function getMaxFileSize(guild) {
|
|||
resolve('100');
|
||||
break;
|
||||
default:
|
||||
resolve('8');
|
||||
reject('An error has occured');
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue