|
25 | 25 | from __future__ import annotations |
26 | 26 |
|
27 | 27 | 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 |
29 | 29 | from urllib.parse import urljoin |
30 | 30 |
|
31 | 31 | from tidalapi.types import JsonObj |
@@ -142,6 +142,28 @@ def playlists(self) -> List[Union["Playlist", "UserPlaylist"]]: |
142 | 142 | ), |
143 | 143 | ) |
144 | 144 |
|
| 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 | + |
145 | 167 | def playlist_and_favorite_playlists( |
146 | 168 | self, offset: int = 0 |
147 | 169 | ) -> List[Union["Playlist", "UserPlaylist"]]: |
|
0 commit comments