From 507f03e716478fce3ee9b9c3f3f5964c34b5b2dd Mon Sep 17 00:00:00 2001 From: Samlon Date: Fri, 25 Jul 2025 19:36:56 +0200 Subject: play.py fix --- cogs/music/play_compressed.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'cogs/music/play_compressed.py') diff --git a/cogs/music/play_compressed.py b/cogs/music/play_compressed.py index f14d75b..0d4901c 100644 --- a/cogs/music/play_compressed.py +++ b/cogs/music/play_compressed.py @@ -25,8 +25,8 @@ class GrajcujZkompresowane(commands.Cog): @staticmethod def compress_audio(input_path): base, ext = os.path.splitext(input_path) - output_path = f"{base}_compressed{ext}" - ffmpeg_command = f"ffmpeg -i {input_path} -ar 8000 -ac 1 -b:a 500 -acodec libmp3lame -q:a 9 {output_path}" + output_path = f"{base}_compressed.opus" + ffmpeg_command = f"ffmpeg -i {input_path} -ac 1 -b:a 500 -acodec libopus {output_path}" subprocess.run(ffmpeg_command, check=True, shell=True) return output_path @@ -57,7 +57,7 @@ class GrajcujZkompresowane(commands.Cog): url = video['link'] filename = f"{video_id}.mp3" file_path = os.path.join(music_dir, filename) - compressed_file_path = os.path.join(music_dir, f"{video_id}_compressed.mp3") + compressed_file_path = os.path.join(music_dir, f"{video_id}_compressed.opus") if os.path.exists(compressed_file_path): found_file = compressed_file_path found_title = title @@ -82,11 +82,20 @@ class GrajcujZkompresowane(commands.Cog): found_file = compressed_file_path found_title = title title = found_title - if not vc.is_playing(): - vc.play(discord.FFmpegPCMAudio(found_file)) - await ctx.followup.send(f"gra (zkompresowane): {title}") - else: - await ctx.followup.send(f"dodano do koleyjki (zkompresowane): {title}") + def after_playing(error): + if error: + print(f'Player error: {error}') + coro = vc.disconnect() + fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) + try: + fut.result() + except Exception as e: + print(f'Error disconnecting: {e}') + + if vc.is_playing() or vc.is_paused(): + vc.stop() + vc.play(discord.FFmpegPCMAudio(found_file), after=after_playing) + await ctx.followup.send(f"gra (zkompresowane): {title}") def setup(bot): -- cgit v1.2.3