Improved Quartessa as we are now calling her, with Album art, thumbs up/down for songs. Plans to add 24/7 mode

This commit is contained in:
Dan 2025-01-23 10:07:40 -05:00
parent bd5e814306
commit fb9c3d68de

View File

@ -120,8 +120,8 @@ async def fetch_and_queue_song(interaction: discord.Interaction, query: str):
async def play_next(interaction: discord.Interaction): async def play_next(interaction: discord.Interaction):
guild_id = interaction.guild.id guild_id = interaction.guild.id
# If no songs are left in the queue
if guild_id not in music_queues or not music_queues[guild_id]: if guild_id not in music_queues or not music_queues[guild_id]:
# If no songs are left in the queue
if guild_id in now_playing_messages and now_playing_messages[guild_id]: if guild_id in now_playing_messages and now_playing_messages[guild_id]:
try: try:
message = await interaction.channel.fetch_message(now_playing_messages[guild_id]) message = await interaction.channel.fetch_message(now_playing_messages[guild_id])
@ -139,10 +139,6 @@ async def play_next(interaction: discord.Interaction):
song_url, title, duration = music_queues[guild_id].pop(0) song_url, title, duration = music_queues[guild_id].pop(0)
current_tracks[guild_id] = (song_url, title) current_tracks[guild_id] = (song_url, title)
# Stop any existing progress bar task
if guild_id in progress_tasks:
progress_tasks[guild_id].cancel()
# Prepare FFmpeg options # Prepare FFmpeg options
ffmpeg_options = { ffmpeg_options = {
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
@ -163,29 +159,33 @@ async def play_next(interaction: discord.Interaction):
), ),
) )
# Update or create the "Now Playing" embed # Create the enhanced embed
embed = discord.Embed( embed = discord.Embed(
title="🎵 Now Playing", title="🎵 Now Playing",
description=f"**{title}**\n\n`00:00 / {time.strftime('%M:%S', time.gmtime(duration))}`", description=f"**{title}**\n\n`00:00 / {time.strftime('%M:%S', time.gmtime(duration))}`",
color=discord.Color.green() color=discord.Color.green()
) )
embed.set_thumbnail(url="https://img.youtube.com/vi/{}/0.jpg".format(song_url.split("?v=")[-1])) # Thumbnail
embed.add_field(name="Artist", value=artist, inline=True)
embed.set_footer(text="React with 👍 or 👎 to rate this song!")
view = PlaybackControls(interaction, guild_id) view = PlaybackControls(interaction, guild_id)
# Update or send the embed
if guild_id in now_playing_messages and now_playing_messages[guild_id]: if guild_id in now_playing_messages and now_playing_messages[guild_id]:
try: try:
message = await interaction.channel.fetch_message(now_playing_messages[guild_id]) message = await interaction.channel.fetch_message(now_playing_messages[guild_id])
await message.edit(embed=embed, view=view) await message.edit(embed=embed, view=view)
except discord.NotFound: except discord.NotFound:
# If the message was deleted, send a new one
message = await interaction.followup.send(embed=embed, view=view) message = await interaction.followup.send(embed=embed, view=view)
now_playing_messages[guild_id] = message.id now_playing_messages[guild_id] = message.id
else: else:
message = await interaction.followup.send(embed=embed, view=view) message = await interaction.followup.send(embed=embed, view=view)
now_playing_messages[guild_id] = message.id now_playing_messages[guild_id] = message.id
# Start updating the progress bar
# Start the progress bar task
start_time = time.time() start_time = time.time()
progress_tasks[guild_id] = asyncio.create_task(update_progress_bar(interaction, duration, start_time)) asyncio.create_task(update_progress_bar(interaction, duration, start_time))
except Exception as e: except Exception as e:
await interaction.followup.send(f"❌ **Error:** Could not play the next song. {str(e)}") await interaction.followup.send(f"❌ **Error:** Could not play the next song. {str(e)}")
@ -215,7 +215,7 @@ async def update_progress_bar(interaction: discord.Interaction, duration: int, s
await message.edit(embed=embed) await message.edit(embed=embed)
except discord.NotFound: except discord.NotFound:
break break
await asyncio.sleep(2) await asyncio.sleep(1)
except asyncio.CancelledError: except asyncio.CancelledError:
pass pass