diff --git a/lib/music_library/artists.ex b/lib/music_library/artists.ex index 1708b8c1..9a8b8cd9 100644 --- a/lib/music_library/artists.ex +++ b/lib/music_library/artists.ex @@ -162,6 +162,11 @@ defmodule MusicLibrary.Artists do |> Repo.update() end + def favicon_url(external_link) do + uri = URI.parse(external_link.url) + "https://www.google.com/s2/favicons?domain=#{uri.host}&sz=16" + end + defp get_collected_artist_ids do q = from ar in ArtistRecord, diff --git a/lib/music_library/artists/artist_info.ex b/lib/music_library/artists/artist_info.ex index 7ab1fbc5..bc637017 100644 --- a/lib/music_library/artists/artist_info.ex +++ b/lib/music_library/artists/artist_info.ex @@ -62,4 +62,17 @@ defmodule MusicLibrary.Artists.ArtistInfo do image["type"] == type end) end + + def relation_urls(artist_info, pattern \\ nil) do + case get_in(artist_info.musicbrainz_data, ["relations", Access.all(), "url", "resource"]) do + nil -> [] + urls -> filter_urls(urls, pattern) + end + end + + defp filter_urls(urls, nil), do: urls + + defp filter_urls(urls, pattern) do + Enum.filter(urls, fn url -> String.contains?(url, pattern) end) + end end diff --git a/lib/music_library_web/live/artist_live/show.ex b/lib/music_library_web/live/artist_live/show.ex index 387c9501..9ee8a3e0 100644 --- a/lib/music_library_web/live/artist_live/show.ex +++ b/lib/music_library_web/live/artist_live/show.ex @@ -205,6 +205,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do |> assign(:current_section, :artists) |> assign(:artist, artist) |> assign(:artist_info, artist_info) + |> assign(:external_links, external_links(artist_info)) |> assign(:country, ArtistInfo.country(artist_info)) |> assign_async(:lastfm_artist_info, fn -> with {:ok, lastfm_artist_info} <- LastFm.get_artist_info(artist.musicbrainz_id, artist.name) do @@ -362,4 +363,20 @@ defmodule MusicLibraryWeb.ArtistLive.Show do attributes: [class: "mt-2 text-sm/7"] ) end + + @external_link_patterns %{ + "ProgArchives" => "progarchives.com" + } + + defp external_links(artist_info) do + Enum.reduce(@external_link_patterns, [], fn {name, pattern}, acc -> + case ArtistInfo.relation_urls(artist_info, pattern) do + [] -> + acc + + [url | _rest] -> + [%{name: name, url: url} | acc] + end + end) + end end diff --git a/lib/music_library_web/live/artist_live/show.html.heex b/lib/music_library_web/live/artist_live/show.html.heex index 8eb902a3..36fa7fc1 100644 --- a/lib/music_library_web/live/artist_live/show.html.heex +++ b/lib/music_library_web/live/artist_live/show.html.heex @@ -173,6 +173,33 @@ {render_bio(lastfm_artist_info.bio)} +
+ {gettext("External links")} +
+
+ <.button + :for={external_link <- @external_links} + href={external_link.url} + target="_blank" + rel="noopener noreferrer" + variant="ghost" + size="sm" + class="ml-2 first:ml-0" + > + {external_link.name} + + {external_link.name} + + +
<.record_grid diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index cdee17e7..82afd4fb 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -1468,3 +1468,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "You need to connect your Last.fm account to scrobble. Please set up your Last.fm session key in the settings." msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex +#, elixir-autogen, elixir-format +msgid "External links" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index d7fb58fa..f82c4f44 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -1468,3 +1468,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "You need to connect your Last.fm account to scrobble. Please set up your Last.fm session key in the settings." msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex +#, elixir-autogen, elixir-format +msgid "External links" +msgstr ""