Compare commits

..

3 commits

Author SHA1 Message Date
de6e0dd3c7 fix getVideoSize 2023-04-20 19:54:21 +02:00
4e5324155d Fix some occasional error 2023-04-20 19:51:03 +02:00
65eb5b997f Tweet is not feedback 2023-04-20 19:50:41 +02:00
3 changed files with 26 additions and 16 deletions

View file

@ -16,10 +16,10 @@ const Blacklists = db.Blacklists;
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('tweet') .setName('tweet')
.setDescription('Send tweet from Haha yes twitter account. Please do not use it for advertisement and keep it english') .setDescription('Send tweet from the bot twitter account. Please do not use it for advertisement and keep it english')
.addStringOption(option => .addStringOption(option =>
option.setName('content') option.setName('content')
.setDescription('The content of the tweet you want to send me.') .setDescription('!THIS IS NOT FEEDBACK! The content of the tweet you want to send me.')
.setRequired(false)) .setRequired(false))
.addAttachmentOption(option => .addAttachmentOption(option =>
option.setName('image') option.setName('image')

View file

@ -49,15 +49,6 @@ 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 });
} }
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) { if (format) {
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) => {
@ -70,8 +61,8 @@ export default {
resolve(stdout); resolve(stdout);
}); });
}); });
qualitys = JSON.parse(qualitys);
qualitys = JSON.parse(qualitys);
const options = []; const options = [];
qualitys.formats.forEach(f => { qualitys.formats.forEach(f => {
@ -117,11 +108,30 @@ export default {
if (!interactionMenu.isSelectMenu()) return; if (!interactionMenu.isSelectMenu()) return;
if (interactionMenu.customId === `downloadQuality${interaction.user.id}${interaction.id}`) { if (interactionMenu.customId === `downloadQuality${interaction.user.id}${interaction.id}`) {
await interactionMenu.deferReply({ ephemeral: false }); await interactionMenu.deferReply({ ephemeral: false });
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); download(url, interactionMenu, interaction);
} }
}); });
return; return;
} }
const aproxFileSize = await utils.getVideoSize(url);
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, interaction); download(url, interaction);
}, },
}; };

View file

@ -14,7 +14,7 @@ export default {
}; };
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) => {
exec(`./bin/yt-dlp -f ${format} "${urlArg}" -o "${os.tmpdir()}/${output}.%(ext)s" --force-overwrites --no-playlist --remux-video=mp4/webm/mov`, (err, stdout, stderr) => { exec(`./bin/yt-dlp -f "${format}" "${urlArg}" -o "${os.tmpdir()}/${output}.%(ext)s" --force-overwrites --no-playlist --remux-video=mp4/webm/mov`, (err, stdout, stderr) => {
if (err) { if (err) {
reject(stderr); reject(stderr);
} }
@ -68,7 +68,7 @@ async function stringIsAValidurl(s) {
async function compressVideo(input, output, preset) { async function compressVideo(input, output, preset) {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
exec(`./bin/HandBrakeCLI -i '${input}' -Z '${preset}' -o '${os.tmpdir()}/${output}'`, (err, stdout, stderr) => { exec(`./bin/HandBrakeCLI -i "${input}" -Z "${preset}" -o "${os.tmpdir()}/${output}"`, (err, stdout, stderr) => {
if (err) { if (err) {
reject(stderr); reject(stderr);
} }
@ -82,7 +82,7 @@ async function compressVideo(input, output, preset) {
} }
async function getVideoCodec(input) { async function getVideoCodec(input) {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
exec(`ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 ${input}`, (err, stdout, stderr) => { exec(`ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "${input}"`, (err, stdout, stderr) => {
if (err) { if (err) {
reject(stderr); reject(stderr);
} }
@ -96,7 +96,7 @@ async function getVideoCodec(input) {
async function getVideoSize(urlArg, format = 'bestvideo*+bestaudio/best') { async function getVideoSize(urlArg, format = 'bestvideo*+bestaudio/best') {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
exec(`./bin/yt-dlp ${urlArg} -f ${format} -O "%(filesize,filesize_approx)s"`, (err, stdout, stderr) => { exec(`./bin/yt-dlp "${urlArg}" -f "${format}" -O "%(filesize,filesize_approx)s"`, (err, stdout, stderr) => {
if (err) { if (err) {
reject(stderr); reject(stderr);
} }