Skip to content

Commit

Permalink
Add method for getting public user playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
tehkillerbee committed Sep 30, 2024
1 parent 067fa58 commit 7c9b0d3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tidalapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from __future__ import annotations

from copy import copy
from typing import TYPE_CHECKING, Dict, List, Optional, Union, cast
from typing import TYPE_CHECKING, List, Optional, Union, cast
from urllib.parse import urljoin

from tidalapi.types import JsonObj
Expand Down Expand Up @@ -142,6 +142,28 @@ def playlists(self) -> List[Union["Playlist", "UserPlaylist"]]:
),
)

def get_public_playlists(self, offset=0) -> List[Union["Playlist", "UserPlaylist"]]:
"""
Get the (public) playlists created by the user
:return: List of public playlists
"""
params = {"limit": 50, "offset": offset}
endpoint = "user-playlists/%s/public" % self.id
json_obj = self.request.request(
"GET", endpoint, base_url=self.session.config.api_v2_location, params=params
).json()

# The response contains both playlists and user details (followInfo, profile) but we will discard the latter.
playlists = {"items": []}
for index, item in enumerate(json_obj["items"]):
if item["playlist"]:
playlists["items"].append(item["playlist"])

return cast(
List[Union["Playlist", "UserPlaylist"]],
self.request.map_json(playlists, parse=self.playlist.parse_factory),
)

def playlist_and_favorite_playlists(
self, offset: int = 0
) -> List[Union["Playlist", "UserPlaylist"]]:
Expand Down

0 comments on commit 7c9b0d3

Please sign in to comment.