From c687d9fa1d89fef8ddc7150d1487dfef07d11abb Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 20 Apr 2026 15:05:51 +0200 Subject: uploader.py and voice fixes Signed-off-by: salmonik --- cogs/music/audio_playback.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'cogs/music/audio_playback.py') diff --git a/cogs/music/audio_playback.py b/cogs/music/audio_playback.py index 28c6118..1c715de 100644 --- a/cogs/music/audio_playback.py +++ b/cogs/music/audio_playback.py @@ -137,8 +137,16 @@ class AudioPlaybackManager: return absolute_source, display_name, is_url @staticmethod - async def execute_playback(ctx, source, display_name, is_url): - """Execute the actual audio playback.""" + async def execute_playback(ctx, source, display_name, is_url, interrupt=True): + """Execute the actual audio playback. + + Args: + ctx: Discord context + source: Audio source path or URL + display_name: Name to display + is_url: Whether source is a URL + interrupt: If True, stop any currently playing audio. If False, skip if audio is playing. + """ target_channel = await AudioPlaybackManager.validate_voice_channel(ctx) if not target_channel: return False @@ -169,9 +177,12 @@ class AudioPlaybackManager: logger.info(f"Moving to voice channel: {target_channel.name}") await vc.move_to(target_channel) - # Stop any currently playing audio - if vc.is_playing() or vc.is_paused(): # type: ignore[union-attr] + # Stop any currently playing audio (if interrupt is True) + if interrupt and (vc.is_playing() or vc.is_paused()): # type: ignore[union-attr] vc.stop() # type: ignore[union-attr] + elif not interrupt and vc.is_playing(): # type: ignore[union-attr] + logger.info("Audio already playing and interrupt=False, skipping playback") + return False # Prepare audio source ( @@ -232,13 +243,14 @@ class AudioPlaybackManager: return prepared_source, display_name, is_url @staticmethod - async def play(ctx, source, delete_after_play=False): + async def play(ctx, source, delete_after_play=False, interrupt=True): """Play audio from a local file or URL. Args: ctx: Discord context source: Either a local file path or a URL to stream from delete_after_play: If True, delete the file after playing (only for local files) + interrupt: If True, stop any currently playing audio. If False, skip if audio is playing. """ # Validate and prepare source ( @@ -254,7 +266,7 @@ class AudioPlaybackManager: # Execute playback success = await AudioPlaybackManager.execute_playback( - ctx, prepared_source, display_name, is_url + ctx, prepared_source, display_name, is_url, interrupt ) # Cleanup if needed -- cgit v1.2.3 From 0e4c707b2b11b4ec70a000e7a9d3108030fc0c61 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 29 Apr 2026 14:43:08 +0200 Subject: damn short files Signed-off-by: salmonik --- cogs/music/audio_playback.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'cogs/music/audio_playback.py') diff --git a/cogs/music/audio_playback.py b/cogs/music/audio_playback.py index 1c715de..1313d01 100644 --- a/cogs/music/audio_playback.py +++ b/cogs/music/audio_playback.py @@ -192,13 +192,14 @@ class AudioPlaybackManager: source, is_url, display_name ) - # Track if playback failed - playback_failed = {"error": None} + # Track playback state + playback_state = {"error": None, "finished": False} def after_playing(error): if error: - playback_failed["error"] = str(error) + playback_state["error"] = str(error) logger.error(f"Playback error: {error}") + playback_state["finished"] = True # Play the audio vc.play(audio_source, after=after_playing) @@ -208,14 +209,19 @@ class AudioPlaybackManager: # Wait for FFmpeg to attempt connection - errors usually happen within 5 seconds await asyncio.sleep(5) - # Check if playback actually started - if playback_failed["error"]: - logger.error(f"Playback failed: {playback_failed['error']}") + # Check if playback failed to start (not just finished quickly) + if playback_state["error"]: + logger.error(f"Playback failed: {playback_state['error']}") await ctx.followup.send( "eror: Timeout - nie udało się połączyć ze streamem", ephemeral=True ) return False + # If playback finished within 5s, it was a short file - not an error + if playback_state["finished"]: + logger.info(f"Playback completed quickly: {final_display_name}") + return True + if not vc.is_playing(): logger.error(f"Stream failed - not playing after 5s: {source}") await ctx.followup.send( -- cgit v1.2.3