Show artist external links
This commit is contained in:
@@ -162,6 +162,11 @@ defmodule MusicLibrary.Artists do
|
|||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
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
|
defp get_collected_artist_ids do
|
||||||
q =
|
q =
|
||||||
from ar in ArtistRecord,
|
from ar in ArtistRecord,
|
||||||
|
|||||||
@@ -62,4 +62,17 @@ defmodule MusicLibrary.Artists.ArtistInfo do
|
|||||||
image["type"] == type
|
image["type"] == type
|
||||||
end)
|
end)
|
||||||
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
|
end
|
||||||
|
|||||||
@@ -205,6 +205,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
|||||||
|> assign(:current_section, :artists)
|
|> assign(:current_section, :artists)
|
||||||
|> assign(:artist, artist)
|
|> assign(:artist, artist)
|
||||||
|> assign(:artist_info, artist_info)
|
|> assign(:artist_info, artist_info)
|
||||||
|
|> assign(:external_links, external_links(artist_info))
|
||||||
|> assign(:country, ArtistInfo.country(artist_info))
|
|> assign(:country, ArtistInfo.country(artist_info))
|
||||||
|> assign_async(:lastfm_artist_info, fn ->
|
|> assign_async(:lastfm_artist_info, fn ->
|
||||||
with {:ok, lastfm_artist_info} <- LastFm.get_artist_info(artist.musicbrainz_id, artist.name) do
|
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"]
|
attributes: [class: "mt-2 text-sm/7"]
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -173,6 +173,33 @@
|
|||||||
{render_bio(lastfm_artist_info.bio)}
|
{render_bio(lastfm_artist_info.bio)}
|
||||||
</.sheet>
|
</.sheet>
|
||||||
</.async_result>
|
</.async_result>
|
||||||
|
<dt
|
||||||
|
:if={@external_links != []}
|
||||||
|
class="mt-4 text-sm font-medium leading-6 text-zinc-900 dark:text-zinc-400"
|
||||||
|
>
|
||||||
|
{gettext("External links")}
|
||||||
|
</dt>
|
||||||
|
<dd class="mt-4 space-y-2">
|
||||||
|
<.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"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
class="mr-2"
|
||||||
|
src={MusicLibrary.Artists.favicon_url(external_link)}
|
||||||
|
alt={external_link.name}
|
||||||
|
loading="lazy"
|
||||||
|
/>
|
||||||
|
<span class="text-sm font-medium text-zinc-900 dark:text-white">
|
||||||
|
{external_link.name}
|
||||||
|
</span>
|
||||||
|
</.button>
|
||||||
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="md:col-span-7 md:order-1">
|
<div class="md:col-span-7 md:order-1">
|
||||||
<.record_grid
|
<.record_grid
|
||||||
|
|||||||
@@ -1468,3 +1468,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, 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."
|
msgid "You need to connect your Last.fm account to scrobble. Please set up your Last.fm session key in the settings."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/artist_live/show.html.heex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "External links"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -1468,3 +1468,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, 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."
|
msgid "You need to connect your Last.fm account to scrobble. Please set up your Last.fm session key in the settings."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/artist_live/show.html.heex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "External links"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user