The Song
class provides methods to interact with songs in the context of a playlist and allows for operations such as searching, adding, removing, and liking songs.
-
playlist:
PrivatePlaylist | None
An optional instance ofPrivatePlaylist
. If not provided, the client is used directly. -
client:
TLSClient
The client used for making HTTP requests. Defaults to a newTLSClient
instance with certain parameters.
__init__(self, playlist: PrivatePlaylist | None = None, *, client: TLSClient = TLSClient("chrome_120", "", auto_retries=3)) -> None
Initializes the Song
class with an optional PrivatePlaylist
instance and a TLSClient
instance.
- Raises:
ValueError
if no playlist is provided and no client is set.
Searches for songs in the Spotify catalog.
-
Args:
track_id
:str
The ID of the song. Not the URI.
-
Returns:
Mapping[str, Any]
The raw track result. -
Raises:
SongError
if there is an issue retrieving the song or if the response is invalid.
Searches for songs in the Spotify catalog.
-
Args:
query
:str
The search query.limit
:int
The maximum number of results to return. Default is 10.offset
:int
The offset for pagination. Default is 0.
-
Returns:
Mapping[str, Any]
The raw search result. -
Raises:
SongError
if there is an issue retrieving the songs or if the response is invalid.
Generator that fetches songs in chunks.
-
Args:
query
:str
The search query.
-
Returns:
Generator[Mapping[str, Any], None, None]
A generator yielding song results in chunks.
Adds a song to the playlist.
-
Args:
song_id
:str
The ID of the song to add.
-
Raises:
ValueError
if no playlist is set or if the song ID is invalid.
SongError
if there is an issue adding the song.
self,
*,
all_instances: bool = False,
uid: str | None = None,
song_id: str | None = None,
song_name: str | None = None
) -> None` Removes a song from the playlist.
-
Args:
all_instances
:bool
IfTrue
, removes all instances of the song. Onlysong_name
can be used in this case.uid
:str | None
The unique ID of the song to remove.song_id
:str | None
The ID of the song to remove.song_name
:str | None
The name of the song to remove.
-
Raises:
ValueError
if no valid song ID, name, or UID is provided, or if bothsong_id
andall_instances
are provided.
SongError
if the song is not found in the playlist.
Likes a song.
-
Args:
song_id
:str
The ID of the song to like.
-
Raises:
ValueError
if no playlist is set or if the song ID is invalid.
SongError
if there is an issue liking the song.