diff --git a/cogs/basic.py b/cogs/basic.py index b78375d..24ebcc3 100644 --- a/cogs/basic.py +++ b/cogs/basic.py @@ -92,8 +92,8 @@ class Basic(commands.Cog): node = voicelink.NodePool.get_node() if node and node.spotify_client: - tracks: list[voicelink.spotify.Track] = await node.spotify_client.trackSearch(current) - return [app_commands.Choice(name=f"{track.artists} - {track.name}", value=f"{track.artists} - {track.name}") for track in tracks] + tracks: list[voicelink.Track] = await node.spotifySearch(current, requester=interaction.user) + return [app_commands.Choice(name=f"{track.author} - {track.title}", value=f"{track.author} - {track.title}") for track in tracks] @commands.hybrid_command(name="connect", aliases=get_aliases("connect")) @app_commands.describe(channel="Provide a channel to connect.") @@ -211,7 +211,7 @@ class Basic(commands.Cog): query_platform = searchPlatform.get(platform, 'ytsearch') + f":{query}" tracks = await player.get_tracks(query=query_platform, requester=ctx.author) else: - tracks = await player.spotifySearch(query=query, requester=ctx.author) + tracks = await player.node.spotifySearch(query=query, requester=ctx.author) if not tracks: return await ctx.send(player.get_msg('noTrackFound')) diff --git a/voicelink/__init__.py b/voicelink/__init__.py index 75673a8..d48084f 100644 --- a/voicelink/__init__.py +++ b/voicelink/__init__.py @@ -36,4 +36,3 @@ from .pool import * from .queue import * from .placeholders import Placeholders, build_embed from .formatter import encode, decode -from .spotify import * diff --git a/voicelink/player.py b/voicelink/player.py index 7087eab..1482b32 100644 --- a/voicelink/player.py +++ b/voicelink/player.py @@ -434,7 +434,7 @@ class Player(VoiceProtocol): *, requester: Member, search_type: SearchType = SearchType.ytsearch - ): + ) -> Union[List[Track], Playlist]: """Fetches tracks from the node's REST api to parse into Lavalink. If you passed in Spotify API credentials when you created the node, @@ -446,22 +446,6 @@ class Player(VoiceProtocol): """ return await self._node.get_tracks(query, requester=requester, search_type=search_type) - async def spotifySearch(self, query: str, *, requester: Member) -> list: - - try: - tracks = await self._node._spotify_client.trackSearch(query=query) - except Exception as _: - raise TrackLoadError("Not able to find the provided Spotify entity, is it private?") - - return [ Track( - track_id=None, - requester=requester, - search_type=SearchType.ytsearch, - spotify_track=track, - info=track.to_dict() - ) - for track in tracks ] - async def connect(self, *, timeout: float, reconnect: bool, self_deaf: bool = True, self_mute: bool = False): await self.guild.change_voice_state(channel=self.channel, self_deaf=True, self_mute=self_mute) self._node._players[self.guild.id] = self diff --git a/voicelink/pool.py b/voicelink/pool.py index 3292a21..966373b 100644 --- a/voicelink/pool.py +++ b/voicelink/pool.py @@ -30,7 +30,7 @@ import aiohttp from discord import Client, Member from discord.ext.commands import Bot -from typing import Dict, Optional, TYPE_CHECKING, Union +from typing import Dict, Optional, TYPE_CHECKING, Union, List from urllib.parse import quote from . import ( @@ -375,7 +375,7 @@ class Node: *, requester: Member, search_type: SearchType = SearchType.ytsearch - ) -> Union[Track, Playlist]: + ) -> Union[List[Track], Playlist]: """Fetches tracks from the node's REST api to parse into Lavalink. If you passed in Spotify API credentials, you can also pass in a @@ -505,6 +505,29 @@ class Node: requester=requester ) ] + + async def spotifySearch(self, query: str, *, requester: Member) -> Optional[List[Track]]: + try: + if not self.spotify_client: + raise InvalidSpotifyClientAuthorization( + "You did not provide proper Spotify client authorization credentials. " + "If you would like to use the Spotify searching feature, " + "please obtain Spotify API credentials here: https://developer.spotify.com/" + ) + + tracks = await self._spotify_client.trackSearch(query=query) + except Exception as _: + raise TrackLoadError("Not able to find the provided Spotify entity, is it private?") + + return [ + Track( + track_id=None, + requester=requester, + search_type=SearchType.ytsearch, + spotify_track=track, + info=track.to_dict() + ) + for track in tracks ] class NodePool: """The base class for the node pool.