sok.apis.music.lastfm_api
Last.fm API Implementation Support for music search and metadata.
LastFMApi
class LastFMApi(api_key: str)Bases: BaseAPI
Last.fm API for music.
Provides search and metadata retrieval from Last.fm.
Initialize Last.fm API.
Parameters
| Name | Type | Description |
|---|---|---|
api_key | str | Last.fm API key |
Attributes
| Name | Description |
|---|---|
BASE_URL | The base URL for Last.fm API. |
api_key | The Last.fm API key. |
supported_content_typesproperty
List[ContentType]
Get supported content types.
supported_media_typesproperty
List[MediaType]
Get supported media types.
get_album_infoasync
async def get_album_info(artist: str, album: str) -> Dict[str, Any]:Get full album details by artist and album name.
Parameters
| Name | Type | Description |
|---|---|---|
artist | str | Artist name. |
album | str | Album name. |
Returns
Dict[str, Any]Dictionary containing album details.
get_artist_infoasync
async def get_artist_info(artist: str) -> Dict[str, Any]:Get detailed artist information.
Parameters
| Name | Type | Description |
|---|---|---|
artist | str | Artist name. |
Returns
Dict[str, Any]Dictionary containing artist details.
get_detailsasync
async def get_details( item_id: str, content_type: ContentType, **kwargs,) -> Dict[str, Any]:Retrieve details of an item.
Note: For albums, item_id must be 'Artist|Album' as Last.fm needs both.
Parameters
| Name | Type | Description |
|---|---|---|
item_id | str | Item identifier. |
content_type | ContentType | Type of content. |
**kwargs | Additional parameters. |
Returns
Dict[str, Any]Dictionary with item details.
get_related_itemsasync
async def get_related_items( item_id: str, content_type: ContentType, **kwargs,) -> List[Dict[str, Any]]:Retrieve related items.
For an ALBUM, returns tracks.
Parameters
| Name | Type | Description |
|---|---|---|
item_id | str | Item identifier. |
content_type | ContentType | Type of content. |
**kwargs | Additional parameters. |
Returns
List[Dict[str, Any]]List of related items.
searchasync
async def search( query: str, content_type: ContentType, **kwargs,) -> Dict[str, Any]:Search for music content.
Parameters
| Name | Type | Description |
|---|---|---|
query | str | Search query. |
content_type | ContentType | Type of content (ALBUM, ARTIST, TRACK). |
**kwargs | Additional parameters including 'limit'. |
Returns
Dict[str, Any]Dictionary with 'results' key containing search results.
search_albumasync
async def search_album(query: str, limit: int = 20) -> List[Dict[str, Any]]:Search for albums on Last.fm.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
query | str | Album search query. | |
limit | int | 20 | Maximum number of results. |
Returns
List[Dict[str, Any]]List of album dictionaries.
search_artistasync
async def search_artist(query: str, limit: int = 20) -> List[Dict[str, Any]]:Search for artists on Last.fm.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
query | str | Artist search query. | |
limit | int | 20 | Maximum number of results. |
Returns
List[Dict[str, Any]]List of artist dictionaries.
search_trackasync
async def search_track( title: str, limit: int = 20, artist: Optional[str] = None,) -> List[Dict[str, Any]]:Search for tracks on Last.fm.
Last.fm does not give the album of a track in its search results.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
title | str | Track title, or free search text. | |
limit | int | 20 | Maximum number of results. |
artist | Optional[str] | None | Artist name, to narrow the search. |
Returns
List[Dict[str, Any]]List of track dictionaries.