getVideoSize

This commit is contained in:
Supositware 2023-04-11 20:16:18 +02:00
parent 3780fad9ae
commit f294e8cee1

View file

@ -9,6 +9,7 @@ export default {
stringIsAValidurl, stringIsAValidurl,
compressVideo, compressVideo,
getVideoCodec, getVideoCodec,
getVideoSize,
getMaxFileSize, getMaxFileSize,
}; };
async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') { async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') {
@ -93,10 +94,23 @@ async function getVideoCodec(input) {
}); });
} }
async function getMaxFileSize(guild) { async function getVideoSize(urlArg, format = 'bestvideo*+bestaudio/best') {
return await new Promise((resolve, reject) => { 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) => {
const tier = guild.premiumTier; const tier = guild.premiumTier;
console.log(tier);
switch (tier) { switch (tier) {
case 0: case 0:
case 1: case 1:
@ -109,7 +123,7 @@ async function getMaxFileSize(guild) {
resolve('100'); resolve('100');
break; break;
default: default:
reject('An error has occured'); resolve('8');
break; break;
} }
}); });