Integrate refresh of Last.fm data (both per artist and batch)

This commit is contained in:
Claudio Ortolina
2026-03-01 09:46:27 +00:00
parent 84323e5732
commit 6836cf5c9e
8 changed files with 146 additions and 6 deletions
@@ -198,6 +198,18 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
/>
{gettext("Refresh Wikipedia")}
</.dropdown_link>
<.dropdown_link
id={"actions-#{@artist.musicbrainz_id}-refresh-lastfm"}
phx-click={JS.push("refresh_lastfm_data", value: %{id: @artist.musicbrainz_id})}
>
<.icon
name="hero-arrow-path"
class="h-4 w-4 mr-1 phx-click-loading:animate-spin"
aria-hidden="true"
data-slot="icon"
/>
{gettext("Refresh Last.fm")}
</.dropdown_link>
</.focus_wrap>
</.dropdown>
</.button_group>
@@ -444,6 +456,14 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
data: @artist_info.wikipedia_data,
type: :json
}
),
if(@artist_info.lastfm_data != %{},
do: %{
name: "lastfm",
title: gettext("Last.fm"),
data: @artist_info.lastfm_data,
type: :json
}
)
],
& &1
@@ -538,6 +558,28 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
end
end
def handle_event("refresh_lastfm_data", %{"id" => id}, socket) do
case Artists.fetch_lastfm_data(id) do
{:ok, artist_info} ->
id
|> Records.get_artist_records()
|> Enum.each(&Records.generate_embedding_async/1)
{:noreply,
socket
|> assign(:artist_info, artist_info)
|> put_toast(:info, gettext("Last.fm data refreshed successfully"))}
{:error, reason} ->
{:noreply,
socket
|> put_toast(
:error,
gettext("Error refreshing Last.fm data") <> "," <> inspect(reason)
)}
end
end
def handle_event("refresh_artist_image", %{"id" => id}, socket) do
case Artists.fetch_image(id) do
{:ok, artist_info} ->