Compare commits
No commits in common. "d118b3cd1f5c67d176394263f320ae14c27d73cd" and "73a8c6653c77494a7cb140315bfbb3cbcff19df9" have entirely different histories.
d118b3cd1f
...
73a8c6653c
4 changed files with 13 additions and 29 deletions
|
@ -11,7 +11,7 @@ export default {
|
||||||
.setDescription('Download a video.')
|
.setDescription('Download a video.')
|
||||||
.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')
|
||||||
|
@ -22,9 +22,9 @@ export default {
|
||||||
await interaction.deferReply({ ephemeral: false });
|
await interaction.deferReply({ ephemeral: false });
|
||||||
const url = interaction.options.getString('url');
|
const url = interaction.options.getString('url');
|
||||||
|
|
||||||
if (!await utils.stringIsAValidurl(url)) {
|
const urlRE = new RegExp('([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?([^ ])+');
|
||||||
console.error(`Not a url!!! ${url}`);
|
if (!url.match(urlRE)) {
|
||||||
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('advanced')) {
|
if (interaction.options.getBoolean('advanced')) {
|
||||||
|
@ -92,7 +92,7 @@ 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')
|
||||||
.setAuthor({ name: `Downloaded by ${interaction.user.tag}`, iconurl: interaction.user.avatarURL(), url: url })
|
.setAuthor({ name: `Downloaded by ${interaction.user.tag}`, iconURL: interaction.user.avatarURL(), url: url })
|
||||||
.setFooter({ text: `You can get the original video by clicking on the "Downloaded by ${interaction.user.tag}" message!` });
|
.setFooter({ text: `You can get the original video by clicking on the "Downloaded by ${interaction.user.tag}" message!` });
|
||||||
|
|
||||||
if (interaction.customId === 'downloadQuality') {
|
if (interaction.customId === 'downloadQuality') {
|
||||||
|
@ -113,12 +113,12 @@ async function download(url, interaction) {
|
||||||
await interaction.followUp('Uh oh! The video you tried to download is too big!', { ephemeral: true });
|
await interaction.followUp('Uh oh! The video you tried to download is too big!', { ephemeral: true });
|
||||||
}
|
}
|
||||||
else if (fileSize > 8) {
|
else if (fileSize > 8) {
|
||||||
const fileurl = await utils.upload(output)
|
const fileURL = await utils.upload(output)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
await interaction.editReply({ content: 'File was bigger than 8 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 });
|
await interaction.followUp({ content: fileURL, ephemeral: false });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await interaction.editReply({ embeds: [Embed], files: [output], ephemeral: false });
|
await interaction.editReply({ embeds: [Embed], files: [output], ephemeral: false });
|
||||||
|
|
|
@ -18,11 +18,6 @@ export default {
|
||||||
await interaction.deferReply({ ephemeral: false });
|
await interaction.deferReply({ ephemeral: false });
|
||||||
const url = interaction.options.getString('url');
|
const url = interaction.options.getString('url');
|
||||||
|
|
||||||
if (!await utils.stringIsAValidurl(url)) {
|
|
||||||
console.error(`Not a url!!! ${url}`);
|
|
||||||
return interaction.editReply({ content: '❌ This does not look like a valid url!', ephemeral: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.downloadVideo(url, interaction.id)
|
utils.downloadVideo(url, interaction.id)
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const file = fs.readdirSync(os.tmpdir()).filter(fn => fn.startsWith(interaction.id));
|
const file = fs.readdirSync(os.tmpdir()).filter(fn => fn.startsWith(interaction.id));
|
||||||
|
@ -60,7 +55,7 @@ export default {
|
||||||
|
|
||||||
async function gifski(output, input) {
|
async function gifski(output, input) {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
exec(`gifski --quality 70 -o ${output} ${input}`, (err, stdout, stderr) => {
|
exec(`gifski -o ${output} ${input}`, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(stderr);
|
reject(stderr);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +69,7 @@ async function gifski(output, input) {
|
||||||
|
|
||||||
async function gifsicle(input, output) {
|
async function gifsicle(input, output) {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
exec(`gifsicle --colors 256 -i ${input} -o ${output}`, (err, stdout, stderr) => {
|
exec(`gifsicle --scale 0.5 -O3 -i ${input} -o ${output}`, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(stderr);
|
reject(stderr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default {
|
||||||
|
|
||||||
const command = client.commands.get(interaction.commandName);
|
const command = client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
console.log(`\x1b[33m${interaction.user.tag} (${interaction.user.id})\x1b[0m launched command \x1b[33m${interaction.commandName}\x1b[0m`);
|
console.log(`\x1b[33m${interaction.user.tag}\x1b[0m launched command \x1b[33m${interaction.commandName}\x1b[0m`);
|
||||||
|
|
||||||
if (!command) return;
|
if (!command) return;
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,10 @@ export default {
|
||||||
downloadVideo,
|
downloadVideo,
|
||||||
upload,
|
upload,
|
||||||
ffmpeg,
|
ffmpeg,
|
||||||
stringIsAValidurl,
|
|
||||||
};
|
};
|
||||||
async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') {
|
async function downloadVideo(url, output, format = 'bestvideo*+bestaudio/best') {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
exec(`./bin/yt-dlp -f ${format} ${urlArg} -o "${os.tmpdir()}/${output}.%(ext)s" --force-overwrites`, (err, stdout, stderr) => {
|
exec(`./bin/yt-dlp -f ${format} ${url} -o "${os.tmpdir()}/${output}.%(ext)s" --force-overwrites`, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(stderr);
|
reject(stderr);
|
||||||
}
|
}
|
||||||
|
@ -48,13 +47,3 @@ async function ffmpeg(command) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stringIsAValidurl(s) {
|
|
||||||
try {
|
|
||||||
new URL(s);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue