Add function to get similar artists

This commit is contained in:
Claudio Ortolina
2024-12-17 20:44:31 +00:00
parent c60108292a
commit 76605a1114
3 changed files with 62 additions and 1 deletions
+20
View File
@@ -136,6 +136,26 @@ defmodule MusicLibrary.Records do
end
end
def get_similar_artists(artist) do
last_fm_config = last_fm_config()
# Sometimes the artist info cannot be identified with the MusicBrainz ID,
# because Last.fm doesn't have that information. In that case, we try again with the artist name.
case last_fm_config.api.get_similar_artists(
{:musicbrainz_id, artist.musicbrainz_id},
last_fm_config
) do
{:ok, info} ->
{:ok, info}
# TODO: remap error codes
{:error, %{"error" => 6}} ->
last_fm_config.api.get_similar_artists({:name, artist.name}, last_fm_config)
error ->
error
end
end
def get_cover(id) do
q =
from r in Record,