aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/compression.py
diff options
context:
space:
mode:
Diffstat (limited to 'cogs/compression.py')
-rw-r--r--cogs/compression.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/cogs/compression.py b/cogs/compression.py
index ddfa545..75eaf7c 100644
--- a/cogs/compression.py
+++ b/cogs/compression.py
@@ -4,7 +4,9 @@ import subprocess
4 4
5import discord 5import discord
6from discord.ext import commands 6from discord.ext import commands
7import logging
7 8
9logger = logging.getLogger(__name__)
8 10
9def filetype(filename): 11def filetype(filename):
10 mime_type, _ = mimetypes.guess_type(filename) 12 mime_type, _ = mimetypes.guess_type(filename)
@@ -45,6 +47,7 @@ class Compression(commands.Cog):
45 input_path = file_path 47 input_path = file_path
46 output_path = os.path.join(temp_dir, f"better_{plik.filename}") 48 output_path = os.path.join(temp_dir, f"better_{plik.filename}")
47 file_type = filetype(file_path) 49 file_type = filetype(file_path)
50 logger.info(f"Compression started for: {file_type}")
48 if file_type == "Video": 51 if file_type == "Video":
49 # Execute ffmpeg command to compress video 52 # Execute ffmpeg command to compress video
50 ffmpeg_command = f"ffmpeg -i {input_path} -c:v libx264 -crf 51 -b:v 100 -vf 'fps=10' -preset ultrafast -c:a libopus -b:a 500 {output_path}" 53 ffmpeg_command = f"ffmpeg -i {input_path} -c:v libx264 -crf 51 -b:v 100 -vf 'fps=10' -preset ultrafast -c:a libopus -b:a 500 {output_path}"
@@ -68,12 +71,14 @@ class Compression(commands.Cog):
68 ffmpeg_command = img_command 71 ffmpeg_command = img_command
69 else: 72 else:
70 await ctx.respond("Plik jest nieobsługiwany", ephemeral=True) 73 await ctx.respond("Plik jest nieobsługiwany", ephemeral=True)
74 logger.info("Unsupported file type")
71 return 75 return
72 76
73 try: 77 try:
74 subprocess.run(ffmpeg_command, check=True, shell=True) 78 subprocess.run(ffmpeg_command, check=True, shell=True)
75 # Upload the compressed file 79 # Upload the compressed file
76 await ctx.respond(file=discord.File(output_path)) 80 await ctx.respond(file=discord.File(output_path))
81 logger.info(f"Compression completed for: {file_type}")
77 # Delete compressed file 82 # Delete compressed file
78 os.remove(input_path) 83 os.remove(input_path)
79 os.remove(output_path) 84 os.remove(output_path)