sok.apis.music.spotify_api
Spotify API Implementation
SpotifyApi
class SpotifyApi(client_id: str, client_secret: str)Bases: BaseAPI
Spotify API implementation using Client Credentials Flow.
Initialize Spotify API.
Parameters
| Name | Type | Description |
|---|---|---|
client_id | str | Spotify application client ID. |
client_secret | str | Spotify application client secret. |
Attributes
| Name | Type | Description |
|---|---|---|
access_token | Optional[str] | Current OAuth access token. |
client_id | Spotify application client ID. | |
client_secret | Spotify application client secret. |
supported_content_typesproperty
List[ContentType]
Return supported content types.
supported_media_typesproperty
List[MediaType]
Return supported media types.
get_detailsasync
async def get_details( item_id: str, content_type: ContentType, **kwargs,) -> Dict[str, Any]:Get details for a Spotify item.
Parameters
| Name | Type | Description |
|---|---|---|
item_id | str | Spotify item ID. |
content_type | ContentType | Type of item (ALBUM, TRACK, ARTIST). |
**kwargs | Additional parameters. |
Returns
Dict[str, Any]Dictionary with item metadata.
get_related_itemsasync
async def get_related_items( item_id: str, content_type: ContentType, **kwargs,) -> List[Dict[str, Any]]:Get related items (tracks for albums).
Parameters
| Name | Type | Description |
|---|---|---|
item_id | str | Spotify item ID. |
content_type | ContentType | Content type (only ALBUM supported). |
**kwargs | Additional parameters. |
Returns
List[Dict[str, Any]]List of track dictionaries for ALBUM, empty list otherwise.
searchasync
async def search( query: str, content_type: ContentType, **kwargs,) -> Dict[str, Any]:Search on Spotify.
Parameters
| Name | Type | Description |
|---|---|---|
query | str | Search query string. |
content_type | ContentType | Type to search (ALBUM, TRACK, ARTIST). |
**kwargs | Additional parameters including 'limit'. |
Returns
Dict[str, Any]Dictionary with 'results' list of matches.
Attributes
| Name | Value |
|---|---|
logger | logging.getLogger(__name__) |