Compare commits
No commits in common. "44a629c7fcc4bdd90e8c353f1bb99dafa52868ed" and "e8fc57394f57150ba403117be732d907976cfa56" have entirely different histories.
44a629c7fc
...
e8fc57394f
2 changed files with 27 additions and 60 deletions
|
@ -8,10 +8,6 @@ let client;
|
|||
let cleanUp;
|
||||
let maxFileSize;
|
||||
|
||||
let { ytdlpMaxResolution } = process.env;
|
||||
// Convert to number as process.env is always a string
|
||||
ytdlpMaxResolution = Number(ytdlpMaxResolution);
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('download')
|
||||
|
@ -113,24 +109,42 @@ export default {
|
|||
if (interactionMenu.customId === `downloadQuality${interaction.user.id}${interaction.id}`) {
|
||||
await interactionMenu.deferReply({ ephemeral: false });
|
||||
|
||||
await checkSize(url, interactionMenu.values[0], args, interaction);
|
||||
return download(url, interactionMenu, interaction);
|
||||
const aproxFileSize = await utils.getVideoSize(url, interactionMenu.values[0]);
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
download(url, interactionMenu, interaction);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
const newFormat = await checkSize(url, undefined, args, interaction);
|
||||
return download(url, interaction, interaction, newFormat);
|
||||
const aproxFileSize = await utils.getVideoSize(url);
|
||||
|
||||
if (aproxFileSize > 100 && !args.compress) {
|
||||
return 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) {
|
||||
return await interaction.followUp('Uh oh! The video you tried to download is larger than 500 mb!', { ephemeral: true });
|
||||
}
|
||||
|
||||
download(url, interaction);
|
||||
},
|
||||
};
|
||||
|
||||
async function download(url, interaction, originalInteraction, format = undefined) {
|
||||
async function download(url, interaction, originalInteraction) {
|
||||
let format = undefined;
|
||||
const Embed = new EmbedBuilder()
|
||||
.setColor(interaction.member ? interaction.member.displayHexColor : 'Navy')
|
||||
.setAuthor({ name: `Downloaded by ${interaction.user.username}`, iconURL: interaction.user.displayAvatarURL(), url: url })
|
||||
.setFooter({ text: `You can get the original video by clicking on the "Downloaded by ${interaction.user.username}" message!` });
|
||||
|
||||
if (interaction.customId === `downloadQuality${interaction.user.id}${originalInteraction.id}` && !format) {
|
||||
|
||||
if (interaction.customId === `downloadQuality${interaction.user.id}`) {
|
||||
format = interaction.values[0];
|
||||
if (interaction.values[1]) format += '+' + interaction.values[1];
|
||||
}
|
||||
|
@ -189,11 +203,6 @@ async function download(url, interaction, originalInteraction, format = undefine
|
|||
|
||||
Embed.setAuthor({ name: `${Embed.data.author.name} (${fileSize.toFixed(2)} MB)`, iconURL: Embed.data.author.icon_url, url: Embed.data.author.url });
|
||||
|
||||
let message = null;
|
||||
if (interaction.isMessage && interaction.reference !== null) {
|
||||
const channel = client.channels.resolve(interaction.reference.channelId);
|
||||
message = await channel.messages.fetch(interaction.reference.messageId);
|
||||
}
|
||||
|
||||
if (fileSize > 100) {
|
||||
await interaction.deleteReply();
|
||||
|
@ -204,23 +213,13 @@ async function download(url, interaction, originalInteraction, format = undefine
|
|||
.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 });
|
||||
if (interaction.isMessage) {
|
||||
await message.reply({ content: fileurl });
|
||||
cleanUp();
|
||||
}
|
||||
else {
|
||||
await interaction.followUp({ content: fileurl, ephemeral: false });
|
||||
}
|
||||
}
|
||||
else if (interaction.isMessage) {
|
||||
await message.reply({ embeds: [Embed], files: [output] });
|
||||
cleanUp();
|
||||
await interaction.followUp({ content: fileurl, ephemeral: false });
|
||||
}
|
||||
else {
|
||||
await interaction.editReply({ embeds: [Embed], files: [output], ephemeral: false });
|
||||
}
|
||||
if (interaction.isMessage) cleanUp();
|
||||
})
|
||||
.catch(async err => {
|
||||
console.error(err);
|
||||
|
@ -251,30 +250,4 @@ async function compress(input, interaction, embed) {
|
|||
await interaction.editReply({ embeds: [embed], files: [`${os.tmpdir()}/${output}`], ephemeral: false });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function checkSize(url, format, args, interaction, tries = 0) {
|
||||
const resolutions = [144, 240, 360, 480, 720, 1080, 1440, 2160];
|
||||
|
||||
while (tries < 4) {
|
||||
format = `bestvideo[height<=?${resolutions[resolutions.indexOf(ytdlpMaxResolution) - tries]}]+bestaudio/best`;
|
||||
const aproxFileSize = await utils.getVideoSize(url, format);
|
||||
|
||||
if (format || tries >= 4) {
|
||||
if (aproxFileSize > 100 && !args.compress && tries > 4) {
|
||||
return await interaction.followUp(`Uh oh! The video you tried to download is larger than 100 mb (is ${aproxFileSize} mb)! Try again with a lower resolution format.`);
|
||||
}
|
||||
else if (aproxFileSize > 500 && tries > 4) {
|
||||
return await interaction.followUp(`Uh oh! The video you tried to download is larger than 500 mb (is ${aproxFileSize} mb)! Try again with a lower resolution format.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (aproxFileSize < 100) {
|
||||
return format;
|
||||
}
|
||||
|
||||
if (tries < 4 && aproxFileSize > 100) {
|
||||
tries++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
import { exec } from 'node:child_process';
|
||||
const { statusChannel, NODE_ENV } = process.env;
|
||||
import { version } from 'discord.js';
|
||||
|
||||
export default {
|
||||
name: 'ready',
|
||||
|
@ -33,17 +32,12 @@ export default {
|
|||
console.log(`${client.readyAt}`);
|
||||
console.log(`There is \x1b[33m${commandSize}\x1b[0m command loaded.`);
|
||||
console.log(`Running yt-dlp \x1b[33m${ytdlpVersion.replace('\n', '')}\x1b[0m`);
|
||||
console.log(`Running Discord.js \x1b[33m${version}\x1b[0m`);
|
||||
console.log('===========[ READY ]===========');
|
||||
|
||||
// If stats channel settings exist, send bot stats to it
|
||||
if (statusChannel && NODE_ENV !== 'development') {
|
||||
const channel = client.channels.resolve(statusChannel);
|
||||
channel.send(
|
||||
`Ready to serve in ${channelSize} channels on ${guildSize} servers.\n` +
|
||||
`There is ${commandSize} command loaded.\n` +
|
||||
`Running yt-dlp ${ytdlpVersion.replace('\n', '')}\n` +
|
||||
`${client.readyAt}`);
|
||||
channel.send(`Ready to serve in ${channelSize} channels on ${guildSize} servers.\nThere is ${commandSize} command loaded.\nRunning yt-dlp ${ytdlpVersion.replace('\n', '')}\n${client.readyAt}`);
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Reference in a new issue