mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-20 02:26:32 +01:00
Add the option to compress audio
This commit is contained in:
parent
913dfa7153
commit
307b95ebeb
1 changed files with 39 additions and 35 deletions
|
@ -813,7 +813,7 @@ class OtherCog(commands.Cog):
|
||||||
f"\\* URL: <{friendly_url}>\n"
|
f"\\* URL: <{friendly_url}>\n"
|
||||||
f"\\* Load time: {fetch_time:.2f}ms\n"
|
f"\\* Load time: {fetch_time:.2f}ms\n"
|
||||||
f"\\* Screenshot render time: {screenshot_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%'
|
'* Probability of being scat or something else horrifying: 100%'
|
||||||
if ctx.user.id == 1019233057519177778 else ''
|
if ctx.user.id == 1019233057519177778 else ''
|
||||||
|
@ -864,6 +864,7 @@ class OtherCog(commands.Cog):
|
||||||
autocomplete=format_autocomplete,
|
autocomplete=format_autocomplete,
|
||||||
default=""
|
default=""
|
||||||
) = "",
|
) = "",
|
||||||
|
extract_audio: bool = False,
|
||||||
upload_log: bool = False,
|
upload_log: bool = False,
|
||||||
compress_if_possible: bool = False
|
compress_if_possible: bool = False
|
||||||
):
|
):
|
||||||
|
@ -980,6 +981,7 @@ class OtherCog(commands.Cog):
|
||||||
"paths": paths,
|
"paths": paths,
|
||||||
"outtmpl": f"{ctx.user.id}-%(title).50s.%(ext)s",
|
"outtmpl": f"{ctx.user.id}-%(title).50s.%(ext)s",
|
||||||
"trim_file_name": 128,
|
"trim_file_name": 128,
|
||||||
|
"extractaudio": extract_audio,
|
||||||
}
|
}
|
||||||
) as downloader:
|
) as downloader:
|
||||||
try:
|
try:
|
||||||
|
@ -1017,42 +1019,43 @@ class OtherCog(commands.Cog):
|
||||||
continue
|
continue
|
||||||
st = file.stat().st_size
|
st = file.stat().st_size
|
||||||
COMPRESS_FAILED = False
|
COMPRESS_FAILED = False
|
||||||
if compress_if_possible and file.suffix in (".mp4", ".mkv", ".mov"):
|
if st / 1024 / 1024 >= MAX_SIZE_MB or st >= BYTES_REMAINING:
|
||||||
await ctx.edit(
|
if compress_if_possible and file.suffix in (".mp4", ".mkv", ".mov"):
|
||||||
embed=discord.Embed(
|
await ctx.edit(
|
||||||
title="Compressing...",
|
embed=discord.Embed(
|
||||||
description="File name: `%s`\nThis will take a long time." % file.name,
|
title="Compressing...",
|
||||||
colour=discord.Colour.blurple()
|
description="File name: `%s`\nThis will take a long time." % file.name,
|
||||||
)
|
colour=discord.Colour.blurple()
|
||||||
)
|
|
||||||
target = file.with_name(file.name + '.compressed' + file.suffix)
|
|
||||||
ffmpeg_command = [
|
|
||||||
"ffmpeg",
|
|
||||||
"-hide_banner",
|
|
||||||
"-i",
|
|
||||||
str(file),
|
|
||||||
"-crf",
|
|
||||||
"30",
|
|
||||||
"-preset",
|
|
||||||
"slow",
|
|
||||||
str(target)
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
|
||||||
await self.bot.loop.run_in_executor(
|
|
||||||
None,
|
|
||||||
partial(
|
|
||||||
subprocess.run,
|
|
||||||
ffmpeg_command,
|
|
||||||
check=True
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError as e:
|
target = file.with_name(file.name + '.compressed' + file.suffix)
|
||||||
COMPRESS_FAILED = True
|
ffmpeg_command = [
|
||||||
else:
|
"ffmpeg",
|
||||||
file = target
|
"-hide_banner",
|
||||||
st = file.stat().st_size
|
"-i",
|
||||||
if st / 1024 / 1024 >= MAX_SIZE_MB or st >= BYTES_REMAINING:
|
str(file),
|
||||||
|
"-crf",
|
||||||
|
"30",
|
||||||
|
"-preset",
|
||||||
|
"fast",
|
||||||
|
str(target)
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
await self.bot.loop.run_in_executor(
|
||||||
|
None,
|
||||||
|
partial(
|
||||||
|
subprocess.run,
|
||||||
|
ffmpeg_command,
|
||||||
|
check=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
COMPRESS_FAILED = True
|
||||||
|
else:
|
||||||
|
file = target
|
||||||
|
st = file.stat().st_size
|
||||||
|
|
||||||
units = ["B", "KB", "MB", "GB", "TB"]
|
units = ["B", "KB", "MB", "GB", "TB"]
|
||||||
st_r = st
|
st_r = st
|
||||||
while st_r > 1024:
|
while st_r > 1024:
|
||||||
|
@ -1083,6 +1086,7 @@ class OtherCog(commands.Cog):
|
||||||
await ctx.channel.trigger_typing()
|
await ctx.channel.trigger_typing()
|
||||||
embed.description = _desc
|
embed.description = _desc
|
||||||
await ctx.edit(embed=embed, files=files)
|
await ctx.edit(embed=embed, files=files)
|
||||||
|
await ctx.send()
|
||||||
|
|
||||||
async def bgtask():
|
async def bgtask():
|
||||||
await asyncio.sleep(120.0)
|
await asyncio.sleep(120.0)
|
||||||
|
|
Loading…
Reference in a new issue