Skip to content

Commit 7c9b0d3

Browse files
committed
Add method for getting public user playlists
1 parent 067fa58 commit 7c9b0d3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tidalapi/user.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from __future__ import annotations
2626

2727
from copy import copy
28-
from typing import TYPE_CHECKING, Dict, List, Optional, Union, cast
28+
from typing import TYPE_CHECKING, List, Optional, Union, cast
2929
from urllib.parse import urljoin
3030

3131
from tidalapi.types import JsonObj
@@ -142,6 +142,28 @@ def playlists(self) -> List[Union["Playlist", "UserPlaylist"]]:
142142
),
143143
)
144144

145+
def get_public_playlists(self, offset=0) -> List[Union["Playlist", "UserPlaylist"]]:
146+
"""
147+
Get the (public) playlists created by the user
148+
:return: List of public playlists
149+
"""
150+
params = {"limit": 50, "offset": offset}
151+
endpoint = "user-playlists/%s/public" % self.id
152+
json_obj = self.request.request(
153+
"GET", endpoint, base_url=self.session.config.api_v2_location, params=params
154+
).json()
155+
156+
# The response contains both playlists and user details (followInfo, profile) but we will discard the latter.
157+
playlists = {"items": []}
158+
for index, item in enumerate(json_obj["items"]):
159+
if item["playlist"]:
160+
playlists["items"].append(item["playlist"])
161+
162+
return cast(
163+
List[Union["Playlist", "UserPlaylist"]],
164+
self.request.map_json(playlists, parse=self.playlist.parse_factory),
165+
)
166+
145167
def playlist_and_favorite_playlists(
146168
self, offset: int = 0
147169
) -> List[Union["Playlist", "UserPlaylist"]]:

0 commit comments

Comments
 (0)