aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/music/play.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cogs/music/play.py44
1 files changed, 37 insertions, 7 deletions
diff --git a/cogs/music/play.py b/cogs/music/play.py
index 7066ae8..b7d409d 100644
--- a/cogs/music/play.py
+++ b/cogs/music/play.py
@@ -1,4 +1,8 @@
1import os
2
1import discord 3import discord
4import mutagen
5
2from . import play_utils 6from . import play_utils
3from discord.ext import commands 7from discord.ext import commands
4import logging 8import logging
@@ -10,13 +14,39 @@ class Play(commands.Cog):
10 self.bot = bot 14 self.bot = bot
11 15
12 @discord.slash_command(name="grajcuj", description="grajcujmy wszyscy!") 16 @discord.slash_command(name="grajcuj", description="grajcujmy wszyscy!")
13 async def play(self, ctx: discord.ApplicationContext, query: str = discord.Option(str, "co zagrać??", required=True)): 17 async def play(
14 await ctx.defer() 18 self,
15 url, title = await play_utils.PlayUtils(self.bot).get_url(ctx, query) 19 ctx: discord.ApplicationContext,
16 logger.info(f"Found video: {title}") 20 query: str = discord.Option(str, "co zagrać??", required=True),
17 filename = await play_utils.PlayUtils(self.bot).download(ctx, url) 21 source: str = discord.Option(str, "co zagrać??", required=True, choices=["local", "soundcloud", "youtube"])
18 logger.info(f"Downloaded file: {filename}") 22
19 await play_utils.PlayUtils(self.bot).play(ctx, filename, title) 23 ):
24 await ctx.defer(ephemeral=True)
25 if source == "local":
26 candidates = await play_utils.PlayUtils(self.bot).search_local(query)
27 if candidates:
28 embed = discord.Embed(title="Wyniki wyszukiwania", description="Wybierz plik do odtworzenia:", color=discord.Color.blue())
29 view = discord.ui.View(disable_on_timeout=True)
30 for i, candidate in enumerate(candidates, start=1):
31 filename = os.path.basename(candidate)
32 metadata = None
33 if os.path.splitext(filename)[1].lower() in ['.mp3', '.wav', '.opus']:
34 metadata = mutagen.File(candidate)
35 title = metadata.get('title', None)
36 if metadata and title:
37 embed.add_field(name=f"{i}. {title}", value="\u200b", inline=False)
38 else:
39 embed.add_field(name=f"{i}. {filename}", value="\u200b", inline=False)
40 button = discord.ui.Button(label=f"Play {i}")
41 async def button_callback(interaction: discord.Interaction, candidate=candidate):
42 await play_utils.PlayUtils(self.bot).play(ctx, candidate)
43 button.callback = button_callback
44 view.add_item(button)
45 await ctx.respond(embed=embed, view=view, ephemeral=True)
46 else:
47 await ctx.respond("Nie znaleziono pliku do odtworzenia", ephemeral=True)
48
49
20 50
21 @discord.slash_command(name="grajcuj_zkompresowane", description="grajcujmy wszyscy w wysokiej jakosci!") 51 @discord.slash_command(name="grajcuj_zkompresowane", description="grajcujmy wszyscy w wysokiej jakosci!")
22 async def play_compressed(self, ctx: discord.ApplicationContext, url: str = discord.Option(str, "co zagrać??", required=True)): 52 async def play_compressed(self, ctx: discord.ApplicationContext, url: str = discord.Option(str, "co zagrać??", required=True)):