Skip to content

Commit

Permalink
Remove return_first, set thumbnail on fetch, remove prefix for URL ba…
Browse files Browse the repository at this point in the history
…sed searches.
  • Loading branch information
EvieePy committed Jun 15, 2023
1 parent d6dfa85 commit 6848113
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions wavelink/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ async def search(cls,
query: str,
/,
*,
return_first: Literal[False] = ...,
node: Node | None = ...
) -> list[Self]:
...
Expand All @@ -149,7 +148,6 @@ async def search(cls,
query: str,
/,
*,
return_first: Literal[True] = ...,
node: Node | None = ...
) -> Self:
...
Expand All @@ -160,7 +158,6 @@ async def search(cls,
query: str,
/,
*,
return_first: bool = ...,
node: Node | None = ...
) -> Self | list[Self]:
...
Expand All @@ -171,7 +168,6 @@ async def search(cls,
query: str,
/,
*,
return_first: bool = ...,
node: Node | None = ...
) -> YouTubePlaylist:
...
Expand All @@ -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.
Expand All @@ -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`.
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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


Expand Down

0 comments on commit 6848113

Please sign in to comment.