From 6848113d03d642f9924c161d826bc1304953f594 Mon Sep 17 00:00:00 2001 From: EvieePy Date: Thu, 15 Jun 2023 10:31:35 +1000 Subject: [PATCH] Remove return_first, set thumbnail on fetch, remove prefix for URL based searches. --- wavelink/tracks.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/wavelink/tracks.py b/wavelink/tracks.py index 9e4e5647..5fa7ebb2 100644 --- a/wavelink/tracks.py +++ b/wavelink/tracks.py @@ -138,7 +138,6 @@ async def search(cls, query: str, /, *, - return_first: Literal[False] = ..., node: Node | None = ... ) -> list[Self]: ... @@ -149,7 +148,6 @@ async def search(cls, query: str, /, *, - return_first: Literal[True] = ..., node: Node | None = ... ) -> Self: ... @@ -160,7 +158,6 @@ async def search(cls, query: str, /, *, - return_first: bool = ..., node: Node | None = ... ) -> Self | list[Self]: ... @@ -171,7 +168,6 @@ async def search(cls, query: str, /, *, - return_first: bool = ..., node: Node | None = ... ) -> YouTubePlaylist: ... @@ -181,7 +177,6 @@ async def search(cls, query: str, /, *, - return_first: bool = False, node: Node | None = None ) -> Self | list[Self]: """Search and retrieve tracks for the given query. @@ -190,8 +185,6 @@ async def search(cls, ---------- query: str The query to search for. - return_first: Optional[bool] - Whether to return the first track from the search results. Defaults to False. node: Optional[:class:`wavelink.Node`] The node to use when searching for tracks. If no :class:`wavelink.Node` is passed, one will be fetched via the :class:`wavelink.NodePool`. @@ -204,16 +197,10 @@ async def search(cls, playlist = await NodePool.get_playlist(query, cls=YouTubePlaylist, node=node) return playlist + elif check.host: + tracks = await NodePool.get_tracks(query, cls=cls, node=node) else: tracks = await NodePool.get_tracks(f'{cls.PREFIX}{query}', cls=cls, node=node) - - try: - track = tracks[0] - except IndexError: - raise NoTracksError(f'Your search query "{query}" returned no tracks.') - - if return_first: - return track return tracks @@ -247,6 +234,11 @@ class YouTubeTrack(Playable): PREFIX: str = 'ytsearch:' + def __init__(self, data: TrackPayload) -> None: + super().__init__(data) + + self._thumb: str = f"https://img.youtube.com/vi/{self.identifier}/maxresdefault.jpg" + @property def thumbnail(self) -> str: """The URL to the thumbnail of this video. @@ -261,13 +253,15 @@ def thumbnail(self) -> str: str The URL to the video thumbnail. """ - return f"https://img.youtube.com/vi/{self.identifier}/maxresdefault.jpg" + return self._thumb thumb = thumbnail async def fetch_thumbnail(self, *, node: Node | None = None) -> str: """Fetch the max resolution thumbnail with a fallback if it does not exist. + This sets and overrides the default ``thumbnail`` and ``thumb`` properties. + .. note:: This method uses an API request to fetch the thumbnail. @@ -287,6 +281,7 @@ async def fetch_thumbnail(self, *, node: Node | None = None) -> str: if resp.status == 404: url = f'https://img.youtube.com/vi/{self.identifier}/hqdefault.jpg' + self._thumb = url return url