Skip to content

Commit

Permalink
Allow YouTubePlaylist to be searched.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Mar 7, 2022
1 parent d9a877c commit 8a4fb12
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions wavelink/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
overload,
)

import yarl
from discord.ext import commands

from .abc import *
Expand Down Expand Up @@ -181,7 +182,13 @@ async def search(
if node is MISSING:
node = NodePool.get_node()

if cls._search_type == 'local':
check = yarl.URL(query)

if str(check.host).removeprefix('www.') == 'youtube.com' and check.query.get("list") or \
cls._search_type == 'ytpl':

tracks = await node.get_playlist(cls=YouTubePlaylist, identifier=query)
elif cls._search_type == 'local':
tracks = await node.get_tracks(cls, query)
else:
tracks = await node.get_tracks(cls, f"{cls._search_type}:{query}")
Expand Down Expand Up @@ -233,7 +240,7 @@ class SoundCloudTrack(SearchableTrack):
_search_type: ClassVar[str] = "scsearch"


class YouTubePlaylist(Playlist):
class YouTubePlaylist(SearchableTrack, Playlist):
"""Represents a Lavalink YouTube playlist object.
Attributes
Expand All @@ -246,6 +253,8 @@ class YouTubePlaylist(Playlist):
The selected video in the playlist. This could be ``None``.
"""

_search_type: ClassVar[str] = "ytpl"

def __init__(self, data: dict):
self.tracks: List[YouTubeTrack] = []
self.name: str = data["playlistInfo"]["name"]
Expand Down

0 comments on commit 8a4fb12

Please sign in to comment.