Current section
Files
Jump to
Current section
Files
lib/lastex/album.ex
defmodule Lastex.Album do
@moduledoc """
Functions for the Last.fm Album API methods.
Read functions take the artist name first and the album name second. Write
functions additionally take a session key obtained via `Lastex.Auth`.
"""
@doc """
Fetches metadata and the tracklist for an album (`album.getInfo`).
Pass `username: "name"` to include that user's playcount, or `autocorrect: 1`
to correct a misspelled artist name.
Lastex.Album.info("Opeth", "Blackwater Park")
"""
def info(artist, album, opts \\ []) do
opts
|> Map.new()
|> Map.merge(%{artist: artist, album: album})
|> then(&Lastex.Client.get("album.getInfo", &1))
end
@doc """
Fetches the tags a user has applied to an album (`album.getTags`).
Returns a `Lastex.Page`. Pass `user: "name"` to read another user's tags, or a
session key via `sk` to read your own.
Lastex.Album.tags("Opeth", "Blackwater Park", user: "rj")
"""
def tags(artist, album, opts \\ []) do
opts
|> Map.new()
|> Map.merge(%{artist: artist, album: album})
|> then(&Lastex.Client.get("album.getTags", &1))
|> Lastex.Page.from_response({"tags", "tag"})
end
@doc """
Fetches the most popular tags for an album (`album.getTopTags`).
Returns a `Lastex.Page`.
Lastex.Album.top_tags("Opeth", "Blackwater Park")
"""
def top_tags(artist, album, opts \\ []) do
opts
|> Map.new()
|> Map.merge(%{artist: artist, album: album})
|> then(&Lastex.Client.get("album.getTopTags", &1))
|> Lastex.Page.from_response({"toptags", "tag"})
end
@doc """
Searches for albums by name (`album.search`).
Returns a `Lastex.Page`. Supports `limit` and `page`.
Lastex.Album.search("Blackwater Park", limit: 5)
"""
def search(album, opts \\ []) do
opts
|> Map.new()
|> Map.put(:album, album)
|> then(&Lastex.Client.get("album.search", &1))
|> Lastex.Page.from_search_response({"albummatches", "album"})
end
@doc """
Tags an album with one or more tags (`album.addTags`).
`tags` is a comma-separated string of up to 10 tags. Requires a session key.
Lastex.Album.add_tags("Opeth", "Blackwater Park", "progressive metal", session_key)
"""
def add_tags(artist, album, tags, sk) do
Lastex.Client.post("album.addTags", %{artist: artist, album: album, tags: tags, sk: sk})
end
@doc """
Removes a single tag from an album (`album.removeTag`). Requires a session key.
Lastex.Album.remove_tag("Opeth", "Blackwater Park", "progressive metal", session_key)
"""
def remove_tag(artist, album, tag, sk) do
Lastex.Client.post("album.removeTag", %{artist: artist, album: album, tag: tag, sk: sk})
end
end