Compare commits
No commits in common. "a7cc663a4d502f6c5f4e2a8249bc96e549a7dcf9" and "54ba45defd2b3ab00b830c0ab3925dc38551a0f3" have entirely different histories.
a7cc663a4d
...
54ba45defd
4 changed files with 12 additions and 86 deletions
|
@ -14,12 +14,8 @@ export default {
|
||||||
.setDescription('url of the video you want to download.')
|
.setDescription('url of the video you want to download.')
|
||||||
.setRequired(true))
|
.setRequired(true))
|
||||||
.addBooleanOption(option =>
|
.addBooleanOption(option =>
|
||||||
option.setName('format')
|
option.setName('advanced')
|
||||||
.setDescription('Choose the quality of the video.')
|
.setDescription('Choose the quality of the video.')
|
||||||
.setRequired(false))
|
|
||||||
.addBooleanOption(option =>
|
|
||||||
option.setName('compress')
|
|
||||||
.setDescription('Compress the video?')
|
|
||||||
.setRequired(false)),
|
.setRequired(false)),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
@ -31,7 +27,7 @@ export default {
|
||||||
return interaction.editReply({ content: '❌ This does not look like a valid url!', ephemeral: true });
|
return interaction.editReply({ content: '❌ This does not look like a valid url!', ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.options.getBoolean('format')) {
|
if (interaction.options.getBoolean('advanced')) {
|
||||||
let qualitys = await new Promise((resolve, reject) => {
|
let qualitys = await new Promise((resolve, reject) => {
|
||||||
exec(`./bin/yt-dlp "${url}" --print "%()j"`, (err, stdout, stderr) => {
|
exec(`./bin/yt-dlp "${url}" --print "%()j"`, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -88,7 +84,7 @@ export default {
|
||||||
if (!interactionMenu.isSelectMenu()) return;
|
if (!interactionMenu.isSelectMenu()) return;
|
||||||
if (interactionMenu.customId === 'downloadQuality') {
|
if (interactionMenu.customId === 'downloadQuality') {
|
||||||
await interactionMenu.deferReply({ ephemeral: false });
|
await interactionMenu.deferReply({ ephemeral: false });
|
||||||
download(url, interactionMenu, interaction);
|
download(url, interactionMenu);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -97,7 +93,7 @@ export default {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
async function download(url, interaction, originalInteraction) {
|
async function download(url, interaction) {
|
||||||
let format = 'bestvideo*+bestaudio/best';
|
let format = 'bestvideo*+bestaudio/best';
|
||||||
const Embed = new MessageEmbed()
|
const Embed = new MessageEmbed()
|
||||||
.setColor(interaction.member ? interaction.member.displayHexColor : 'NAVY')
|
.setColor(interaction.member ? interaction.member.displayHexColor : 'NAVY')
|
||||||
|
@ -116,37 +112,6 @@ async function download(url, interaction, originalInteraction) {
|
||||||
|
|
||||||
const fileStat = fs.statSync(output);
|
const fileStat = fs.statSync(output);
|
||||||
const fileSize = fileStat.size / 1000000.0;
|
const fileSize = fileStat.size / 1000000.0;
|
||||||
const compressInteraction = originalInteraction ? originalInteraction : interaction;
|
|
||||||
if (compressInteraction.options.getBoolean('compress')) {
|
|
||||||
const presets = [ 'Discord Tiny 5 Minutes 240p30', 'Discord Small 2 Minutes 360p30', 'Discord Nitro Small 10-20 Minutes 480p30', 'Discord Nitro Medium 5-10 Minutes 720p30', 'Discord Nitro Large 3-6 Minutes 1080p30' ];
|
|
||||||
const options = [];
|
|
||||||
|
|
||||||
presets.forEach(p => {
|
|
||||||
options.push({
|
|
||||||
label: p,
|
|
||||||
value: p,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const row = new MessageActionRow()
|
|
||||||
.addComponents(
|
|
||||||
new MessageSelectMenu()
|
|
||||||
.setCustomId('preset')
|
|
||||||
.setPlaceholder('Nothing selected')
|
|
||||||
.addOptions(options),
|
|
||||||
);
|
|
||||||
|
|
||||||
await interaction.deleteReply();
|
|
||||||
await interaction.followUp({ content: 'Which compression preset do you want?', ephemeral: true, components: [row] });
|
|
||||||
interaction.client.once('interactionCreate', async (interactionMenu) => {
|
|
||||||
if (!interactionMenu.isSelectMenu()) return;
|
|
||||||
if (interactionMenu.customId === 'preset') {
|
|
||||||
await interactionMenu.deferReply({ ephemeral: false });
|
|
||||||
compress(file, interactionMenu, Embed);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileSize > 100) {
|
if (fileSize > 100) {
|
||||||
await interaction.deleteReply();
|
await interaction.deleteReply();
|
||||||
|
@ -171,19 +136,3 @@ async function download(url, interaction, originalInteraction) {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compress(input, interaction, embed) {
|
|
||||||
const output = `compressed${input}.mp4`;
|
|
||||||
utils.compressVideo(`${os.tmpdir()}/${input}`, output, interaction.values[0])
|
|
||||||
.then(async () => {
|
|
||||||
const fileStat = fs.statSync(`${os.tmpdir()}/${output}`);
|
|
||||||
const fileSize = fileStat.size / 1000000.0;
|
|
||||||
|
|
||||||
if (fileSize > 8) {
|
|
||||||
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 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
16
readme.md
16
readme.md
|
@ -12,10 +12,9 @@ You need to install the following
|
||||||
|
|
||||||
|
|
||||||
* ffmpeg (Optional but very recommanded: for yt-dlp to merge video/audio formats)
|
* ffmpeg (Optional but very recommanded: for yt-dlp to merge video/audio formats)
|
||||||
* yt-dlp ([a file can download it for you](prereq.cjs))
|
* yt-dlp ([a file can download it for you](prereq.js))
|
||||||
* HandBrakeCLI (For [download](commands/utility/download.js))
|
* gifsicle (For [vid2gif](commands/vid2gif.js))
|
||||||
* gifsicle (For [vid2gif](commands/utility/vid2gif.js))
|
* giski (For [vid2gif](commands/vid2gif.js))
|
||||||
* gifki (For [vid2gif](commands/utility/vid2gif.js))
|
|
||||||
* Somewhere to upload files larger than 8 mb (I use a self hosted [XBackBone](https://github.com/SergiX44/XBackBone/) with the upload.sh script made from it, you can use anything else just need to be located in bin/upload.sh)
|
* Somewhere to upload files larger than 8 mb (I use a self hosted [XBackBone](https://github.com/SergiX44/XBackBone/) with the upload.sh script made from it, you can use anything else just need to be located in bin/upload.sh)
|
||||||
|
|
||||||
### Installing
|
### Installing
|
||||||
|
@ -26,8 +25,8 @@ git checkout slash
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
To run the bot for the first time you need to execute [deploy-commands.js](scripts/deploy-commands.js) so the commands can be registered, don't forget to set your .env accordingly.
|
To run the bot for the first time you need to execute [deploy-guild-commands.js](deploy-guild-commands.js) so the commands can be registered, don't forget to set your .env accordingly.
|
||||||
``node scripts/deploy-commands.cjs``
|
``node deploy-commands.cjs``
|
||||||
|
|
||||||
then you can just run it normally.
|
then you can just run it normally.
|
||||||
``node index.js``
|
``node index.js``
|
||||||
|
@ -44,9 +43,6 @@ If you are on linux and don't need automatic restart on crash you can just do
|
||||||
|
|
||||||
* [Discord.JS](https://github.com/discordjs/discord.js)
|
* [Discord.JS](https://github.com/discordjs/discord.js)
|
||||||
* [yt-dlp](https://github.com/yt-dlp/yt-dlp)
|
* [yt-dlp](https://github.com/yt-dlp/yt-dlp)
|
||||||
* [HandBrakeCLI](https://github.com/HandBrake/HandBrake)
|
|
||||||
* [gifsicle](https://github.com/kohler/gifsicle)
|
|
||||||
* [gifski](https://github.com/ImageOptim/gifski)
|
|
||||||
|
|
||||||
## Authors
|
## Authors
|
||||||
|
|
||||||
|
@ -54,7 +50,7 @@ If you are on linux and don't need automatic restart on crash you can just do
|
||||||
|
|
||||||
## Donation link
|
## Donation link
|
||||||
|
|
||||||
https://libtar.de/donate.html
|
[![Paypal](https://www.paypalobjects.com/en_US/CH/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/paypalme2/supositware/)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -11,18 +11,14 @@ const commands = [
|
||||||
|
|
||||||
new SlashCommandBuilder()
|
new SlashCommandBuilder()
|
||||||
.setName('download')
|
.setName('download')
|
||||||
.setDescription('Download a video.')
|
.setDescription('Download a video. (100 mb max)')
|
||||||
.addStringOption(option =>
|
.addStringOption(option =>
|
||||||
option.setName('url')
|
option.setName('url')
|
||||||
.setDescription('url of the video you want to download.')
|
.setDescription('URL of the video you want to download.')
|
||||||
.setRequired(true))
|
.setRequired(true))
|
||||||
.addBooleanOption(option =>
|
.addBooleanOption(option =>
|
||||||
option.setName('advanced')
|
option.setName('advanced')
|
||||||
.setDescription('Choose the quality of the video.')
|
.setDescription('Choose the quality of the video.')
|
||||||
.setRequired(false))
|
|
||||||
.addBooleanOption(option =>
|
|
||||||
option.setName('compress')
|
|
||||||
.setDescription('Compress the video?')
|
|
||||||
.setRequired(false)),
|
.setRequired(false)),
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ export default {
|
||||||
upload,
|
upload,
|
||||||
ffmpeg,
|
ffmpeg,
|
||||||
stringIsAValidurl,
|
stringIsAValidurl,
|
||||||
compressVideo,
|
|
||||||
};
|
};
|
||||||
async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') {
|
async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
|
@ -59,17 +58,3 @@ async function stringIsAValidurl(s) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compressVideo(input, output, preset) {
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
exec(`./bin/HandBrakeCLI -i '${input}' -Z '${preset}' -o '${os.tmpdir()}/${output}'`, (err, stdout, stderr) => {
|
|
||||||
if (err) {
|
|
||||||
reject(stderr);
|
|
||||||
}
|
|
||||||
if (stderr) {
|
|
||||||
console.error(stderr);
|
|
||||||
}
|
|
||||||
resolve(stdout);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in a new issue