mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-20 02:26:32 +01:00
Always compress where possible
This commit is contained in:
parent
03743e2f65
commit
d7d6462d6d
1 changed files with 39 additions and 39 deletions
|
@ -1265,47 +1265,47 @@ class OtherCog(commands.Cog):
|
||||||
continue
|
continue
|
||||||
st = file.stat().st_size
|
st = file.stat().st_size
|
||||||
COMPRESS_FAILED = False
|
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"):
|
||||||
if compress_if_possible:
|
await ctx.edit(
|
||||||
await ctx.edit(
|
embed=discord.Embed(
|
||||||
embed=discord.Embed(
|
title="Compressing...",
|
||||||
title="Compressing...",
|
description=str(file),
|
||||||
description=str(file),
|
colour=discord.Colour.blurple()
|
||||||
colour=discord.Colour.blurple()
|
)
|
||||||
|
)
|
||||||
|
target = file.with_name(file.name + '.compressed' + file.suffix)
|
||||||
|
ffmpeg_command = [
|
||||||
|
"ffmpeg",
|
||||||
|
"-i",
|
||||||
|
str(file),
|
||||||
|
"-c",
|
||||||
|
"copy",
|
||||||
|
"-crf",
|
||||||
|
"30",
|
||||||
|
"-preset",
|
||||||
|
"slow",
|
||||||
|
str(target)
|
||||||
|
]
|
||||||
|
try:
|
||||||
|
await self.bot.loop.run_in_executor(
|
||||||
|
None,
|
||||||
|
partial(
|
||||||
|
subprocess.run,
|
||||||
|
ffmpeg_command,
|
||||||
|
capture_output=True,
|
||||||
|
check=True
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
target = file.with_name(file.name + '.compressed' + file.suffix)
|
except subprocess.CalledProcessError as e:
|
||||||
ffmpeg_command = [
|
COMPRESS_FAILED = True
|
||||||
"ffmpeg",
|
else:
|
||||||
"-i",
|
file = target
|
||||||
str(file),
|
st = file.stat().st_size
|
||||||
"-c",
|
if st / 1024 / 1024 <= MAX_SIZE_MB and st < BYTES_REMAINING:
|
||||||
"copy",
|
files.append(discord.File(file, file.name))
|
||||||
"-crf",
|
BYTES_REMAINING -= st
|
||||||
"30",
|
continue
|
||||||
"-preset",
|
if st / 1024 / 1024 >= MAX_SIZE_MB or st >= BYTES_REMAINING:
|
||||||
"slow",
|
|
||||||
str(target)
|
|
||||||
]
|
|
||||||
try:
|
|
||||||
await self.bot.loop.run_in_executor(
|
|
||||||
None,
|
|
||||||
partial(
|
|
||||||
subprocess.run,
|
|
||||||
ffmpeg_command,
|
|
||||||
capture_output=True,
|
|
||||||
check=True
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
COMPRESS_FAILED = True
|
|
||||||
else:
|
|
||||||
file = target
|
|
||||||
st = file.stat().st_size
|
|
||||||
if st / 1024 / 1024 <= MAX_SIZE_MB and st < BYTES_REMAINING:
|
|
||||||
files.append(discord.File(file, file.name))
|
|
||||||
BYTES_REMAINING -= st
|
|
||||||
continue
|
|
||||||
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:
|
||||||
|
|
Loading…
Reference in a new issue