aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/music/play_compressed.py
diff options
context:
space:
mode:
Diffstat (limited to 'cogs/music/play_compressed.py')
-rw-r--r--cogs/music/play_compressed.py25
1 files changed, 17 insertions, 8 deletions
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):
25 @staticmethod 25 @staticmethod
26 def compress_audio(input_path): 26 def compress_audio(input_path):
27 base, ext = os.path.splitext(input_path) 27 base, ext = os.path.splitext(input_path)
28 output_path = f"{base}_compressed{ext}" 28 output_path = f"{base}_compressed.opus"
29 ffmpeg_command = f"ffmpeg -i {input_path} -ar 8000 -ac 1 -b:a 500 -acodec libmp3lame -q:a 9 {output_path}" 29 ffmpeg_command = f"ffmpeg -i {input_path} -ac 1 -b:a 500 -acodec libopus {output_path}"
30 subprocess.run(ffmpeg_command, check=True, shell=True) 30 subprocess.run(ffmpeg_command, check=True, shell=True)
31 return output_path 31 return output_path
32 32
@@ -57,7 +57,7 @@ class GrajcujZkompresowane(commands.Cog):
57 url = video['link'] 57 url = video['link']
58 filename = f"{video_id}.mp3" 58 filename = f"{video_id}.mp3"
59 file_path = os.path.join(music_dir, filename) 59 file_path = os.path.join(music_dir, filename)
60 compressed_file_path = os.path.join(music_dir, f"{video_id}_compressed.mp3") 60 compressed_file_path = os.path.join(music_dir, f"{video_id}_compressed.opus")
61 if os.path.exists(compressed_file_path): 61 if os.path.exists(compressed_file_path):
62 found_file = compressed_file_path 62 found_file = compressed_file_path
63 found_title = title 63 found_title = title
@@ -82,11 +82,20 @@ class GrajcujZkompresowane(commands.Cog):
82 found_file = compressed_file_path 82 found_file = compressed_file_path
83 found_title = title 83 found_title = title
84 title = found_title 84 title = found_title
85 if not vc.is_playing(): 85 def after_playing(error):
86 vc.play(discord.FFmpegPCMAudio(found_file)) 86 if error:
87 await ctx.followup.send(f"gra (zkompresowane): {title}") 87 print(f'Player error: {error}')
88 else: 88 coro = vc.disconnect()
89 await ctx.followup.send(f"dodano do koleyjki (zkompresowane): {title}") 89 fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop)
90 try:
91 fut.result()
92 except Exception as e:
93 print(f'Error disconnecting: {e}')
94
95 if vc.is_playing() or vc.is_paused():
96 vc.stop()
97 vc.play(discord.FFmpegPCMAudio(found_file), after=after_playing)
98 await ctx.followup.send(f"gra (zkompresowane): {title}")
90 99
91 100
92def setup(bot): 101def setup(bot):