Can fetch an artist info from Last.fm

This commit is contained in:
Claudio Ortolina
2024-12-01 18:06:30 +00:00
parent b63b3a633a
commit 2d721774d6
7 changed files with 1975 additions and 4 deletions
+29 -1
View File
@@ -3,7 +3,7 @@ defmodule LastFm.APIImpl do
require Logger
alias LastFm.Track
alias LastFm.{Artist, Track}
@base_url "http://ws.audioscrobbler.com/2.0/"
@@ -44,6 +44,34 @@ defmodule LastFm.APIImpl do
end
end
@impl true
def get_artist_info(artist_mbid, api_key) do
options = [
method: "artist.getInfo",
api_key: api_key,
mbid: artist_mbid,
format: "json",
limit: 50
]
url = @base_url <> "?" <> URI.encode_query(options)
Logger.debug("Fetching data from #{sanitize_url(url, api_key)}")
case json_get(url) do
{:ok, response} ->
{:ok,
response
|> Map.get("artist")
|> Artist.from_api_response()}
other ->
msg = "Failed to fetch data from #{sanitize_url(url, api_key)}, reason: #{inspect(other)}"
Logger.error(msg)
{:error, msg}
end
end
defp json_get(url) do
req =
Finch.build(:get, url, [