From 791e75cb2beeca45a6edf52b65f7e299e03b5eaf Mon Sep 17 00:00:00 2001 From: SamlonDev Date: Sat, 14 Jun 2025 18:54:02 +0200 Subject: code-style issues --- cogs/compression.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'cogs/compression.py') diff --git a/cogs/compression.py b/cogs/compression.py index dfd96ae..ddfa545 100644 --- a/cogs/compression.py +++ b/cogs/compression.py @@ -1,10 +1,10 @@ -import discord -from discord.ext import commands -import asyncio import mimetypes -import os +import os import subprocess -import tempfile + +import discord +from discord.ext import commands + def filetype(filename): mime_type, _ = mimetypes.guess_type(filename) @@ -17,10 +17,11 @@ def filetype(filename): return "Image" return "Unknown" + class Compression(commands.Cog): def __init__(self, bot): self.bot = bot - + @commands.slash_command( name="kompresja", description="skompresuj wideło albo dźwienk :)", @@ -33,14 +34,14 @@ class Compression(commands.Cog): ) async def compression(self, ctx, plik): await ctx.defer() - # Save files to temp directory inside the bot's root directory + # Save files to the temp directory inside the bot's root directory bot_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) temp_dir = os.path.join(bot_dir, "temp") if not os.path.exists(temp_dir): os.makedirs(temp_dir) file_path = os.path.join(temp_dir, plik.filename) await plik.save(file_path) - + input_path = file_path output_path = os.path.join(temp_dir, f"better_{plik.filename}") file_type = filetype(file_path) @@ -51,7 +52,7 @@ class Compression(commands.Cog): ffmpeg_command = f"ffmpeg -i {input_path} -ar 8000 -ac 1 -b:a 16k -acodec libmp3lame -q:a 9 {output_path}" elif file_type == "Image": # Use ImageMagick's magick to heavily compress image (JPEG/PNG/GIF) - # For JPEG: quality 5, strip metadata, resize to 30% of original size + # For JPEG: quality 5, strip metadata, resize to 30% of the original size # For PNG: magick to JPEG, then compress # For GIF: optimize and reduce colors ext = os.path.splitext(input_path)[1].lower() @@ -68,10 +69,10 @@ class Compression(commands.Cog): else: await ctx.respond("Plik jest nieobsługiwany", ephemeral=True) return - + try: subprocess.run(ffmpeg_command, check=True, shell=True) - # Upload compressed file + # Upload the compressed file await ctx.respond(file=discord.File(output_path)) # Delete compressed file os.remove(input_path) @@ -85,4 +86,4 @@ class Compression(commands.Cog): def setup(bot): - bot.add_cog(Compression(bot)) \ No newline at end of file + bot.add_cog(Compression(bot)) -- cgit v1.2.3