The PublicPlaylist
class allows you to access public information about a Spotify playlist without requiring user login.
-
playlist:
str | None
The Spotify URI of the playlist. If provided, it is used to initialize the playlist. -
client:
TLSClient
An instance ofTLSClient
used for making HTTP requests. Defaults to a new instance with specified parameters.
__init__(self, playlist: str | None = None, /, *, client: TLSClient = TLSClient("chrome_120", "", auto_retries=3)) -> None
Initializes the PublicPlaylist
class with an optional playlist URI and a TLSClient
instance.
- Raises:
ValueError
if playlist ID cannot be extracted from the provided URI.
Fetches public information about the playlist.
-
Args:
limit
:int
The maximum number of results to return. Default is 25.offset
:int
The offset for pagination. Default is 0.
-
Returns:
Mapping[str, Any]
The playlist information. -
Raises:
PlaylistError
if there is an issue retrieving the playlist information or if the response is invalid.
Generator that fetches playlist information in chunks.
-
Returns:
Generator[Mapping[str, Any], None, None]
A generator yielding playlist information in chunks. -
Note: If the total number of tracks is 343 or fewer, pagination is not required.
The PrivatePlaylist
class allows you to interact with a playlist while logged in, enabling operations such as adding to and removing from the library, creating, and getting recommendations.
-
login:
Login
The login object used for authenticated requests. -
playlist:
str | None
The Spotify URI of the playlist. If provided, it is used to initialize the playlist.
Initializes the PrivatePlaylist
class with a Login
object and an optional playlist URI.
- Raises:
ValueError
if not logged in or if playlist ID cannot be extracted from the provided URI.
Sets or updates the playlist ID.
-
Args:
playlist
:str
The Spotify URI or ID of the playlist to set.
-
Raises:
ValueError
if the playlist URI is invalid.
Adds the playlist to the user's library.
- Raises:
ValueError
if the playlist ID is not set.
PlaylistError
if there is an issue adding the playlist.
Removes the playlist from the user's library.
- Raises:
ValueError
if the playlist ID is not set.
PlaylistError
if there is an issue removing the playlist.
Deletes the playlist from the user's library. This is the same as removing it from the library.
- Raises:
ValueError
if the playlist ID is not set.
PlaylistError
if there is an issue deleting the playlist.
Fetches all playlists in the user's library.
-
Args:
limit
:int
The maximum number of playlists to return. Default is 50.
-
Returns:
Mapping[str, Any]
The user's library information. -
Raises:
PlaylistError
if there is an issue retrieving the library information.
Creates a new playlist.
-
Args:
name
:str
The name of the new playlist.
-
Returns:
str
The URI of the newly created playlist. -
Raises:
PlaylistError
if there is an issue creating the playlist.
Fetches recommended songs for the playlist.
-
Args:
num_songs
:int
The number of recommended songs to fetch. Default is 20.
-
Returns:
Mapping[str, Any]
The recommended songs. -
Raises:
PlaylistError
if there is an issue retrieving recommended songs.