Add the option to compress audio

This commit is contained in:
Nexus 2023-05-15 18:48:19 +01:00
parent 913dfa7153
commit 307b95ebeb
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -813,7 +813,7 @@ class OtherCog(commands.Cog):
f"\\* URL: <{friendly_url}>\n"
f"\\* Load time: {fetch_time:.2f}ms\n"
f"\\* Screenshot render time: {screenshot_time:.2f}ms\n"
f"\\* Total time: {(fetch_time + screenshot_time):.2f}ms\n"
f"\\* Total time: {(fetch_time + screenshot_time):.2f}ms\n" +
(
'* Probability of being scat or something else horrifying: 100%'
if ctx.user.id == 1019233057519177778 else ''
@ -864,6 +864,7 @@ class OtherCog(commands.Cog):
autocomplete=format_autocomplete,
default=""
) = "",
extract_audio: bool = False,
upload_log: bool = False,
compress_if_possible: bool = False
):
@ -980,6 +981,7 @@ class OtherCog(commands.Cog):
"paths": paths,
"outtmpl": f"{ctx.user.id}-%(title).50s.%(ext)s",
"trim_file_name": 128,
"extractaudio": extract_audio,
}
) as downloader:
try:
@ -1017,6 +1019,7 @@ class OtherCog(commands.Cog):
continue
st = file.stat().st_size
COMPRESS_FAILED = False
if st / 1024 / 1024 >= MAX_SIZE_MB or st >= BYTES_REMAINING:
if compress_if_possible and file.suffix in (".mp4", ".mkv", ".mov"):
await ctx.edit(
embed=discord.Embed(
@ -1034,7 +1037,7 @@ class OtherCog(commands.Cog):
"-crf",
"30",
"-preset",
"slow",
"fast",
str(target)
]
@ -1047,12 +1050,12 @@ class OtherCog(commands.Cog):
check=True
)
)
except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError:
COMPRESS_FAILED = True
else:
file = target
st = file.stat().st_size
if st / 1024 / 1024 >= MAX_SIZE_MB or st >= BYTES_REMAINING:
units = ["B", "KB", "MB", "GB", "TB"]
st_r = st
while st_r > 1024:
@ -1083,6 +1086,7 @@ class OtherCog(commands.Cog):
await ctx.channel.trigger_typing()
embed.description = _desc
await ctx.edit(embed=embed, files=files)
await ctx.send()
async def bgtask():
await asyncio.sleep(120.0)