Skip to content

Commit

Permalink
feat: add playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
ooliver1 committed Sep 21, 2022
1 parent d096e4e commit 7b5e9e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mafic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .__libraries import ExponentialBackoff, dumps, loads
from .errors import TrackLoadException
from .playlist import Playlist
from .track import Track

if TYPE_CHECKING:
Expand Down Expand Up @@ -368,7 +369,7 @@ async def __request(

async def fetch_tracks(
self, query: str, *, search_type: str
) -> list[Track] | None: # TODO: | Playlist
) -> list[Track] | Playlist | None:
if not URL_REGEX.match(query):
query = f"{search_type}:{query}"

Expand All @@ -385,7 +386,7 @@ async def fetch_tracks(
return [Track(**data["tracks"][0])]
elif data["loadType"] == "PLAYLIST_LOADED":
# TODO: handle playlists
...
return Playlist(info=data["playlistInfo"], tracks=data["tracks"])
elif data["loadType"] == "SEARCH_RESULT":
return [Track(**track) for track in data["tracks"]]
elif data["loadType"] == "LOAD_FAILED":
Expand Down
19 changes: 19 additions & 0 deletions mafic/playlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: MIT

from __future__ import annotations

from typing import TYPE_CHECKING

from .track import Track

if TYPE_CHECKING:
from .typings import PlaylistInfo, TrackWithInfo

__all__ = ("Playlist",)


class Playlist:
def __init__(self, *, info: PlaylistInfo, tracks: list[TrackWithInfo]):
self.name: str = info["name"]
self.selected_track: int = info["selectedTrack"]
self.tracks: list[Track] = [Track(**track) for track in tracks]

0 comments on commit 7b5e9e1

Please sign in to comment.