Add play count to LastFm.Artist
This commit is contained in:
@@ -51,6 +51,7 @@ defmodule LastFm.APIImpl do
|
||||
options = [
|
||||
method: "artist.getInfo",
|
||||
api_key: config.api_key,
|
||||
user: config.user,
|
||||
mbid: artist_mbid,
|
||||
format: "json",
|
||||
limit: 50
|
||||
|
||||
+13
-3
@@ -1,11 +1,12 @@
|
||||
defmodule LastFm.Artist do
|
||||
defstruct [:musicbrainz_id, :name, :bio, :image]
|
||||
defstruct [:musicbrainz_id, :name, :bio, :image, :play_count]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
musicbrainz_id: String.t(),
|
||||
name: String.t(),
|
||||
bio: String.t(),
|
||||
image: String.t()
|
||||
image: String.t(),
|
||||
play_count: non_neg_integer()
|
||||
}
|
||||
|
||||
def from_api_response(api_response) do
|
||||
@@ -13,7 +14,8 @@ defmodule LastFm.Artist do
|
||||
musicbrainz_id: api_response["mbid"],
|
||||
name: api_response["name"],
|
||||
bio: api_response["bio"]["summary"],
|
||||
image: get_image(api_response)
|
||||
image: get_image(api_response),
|
||||
play_count: get_play_count(api_response)
|
||||
}
|
||||
end
|
||||
|
||||
@@ -22,4 +24,12 @@ defmodule LastFm.Artist do
|
||||
|> Enum.find(%{"#text" => nil}, fn i -> i["size"] == "medium" end)
|
||||
|> Map.get("#text")
|
||||
end
|
||||
|
||||
defp get_play_count(api_response) do
|
||||
if play_count = get_in(api_response, ["stats", "userplaycount"]) do
|
||||
String.to_integer(play_count)
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user