Support getting artist bios from Wikipedia (experimental)
This commit is contained in:
@@ -101,6 +101,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:artist_info, artist_info)
|
||||
|> assign(:biography, build_biography(artist_info))
|
||||
|> put_toast(:info, gettext("Artist info refreshed successfully"))}
|
||||
|
||||
{:error, reason} ->
|
||||
@@ -113,6 +114,25 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
||||
end
|
||||
end
|
||||
|
||||
def handle_event("refresh_wikipedia_data", %{"id" => id}, socket) do
|
||||
case Artists.refresh_wikipedia_data(id) do
|
||||
{:ok, artist_info} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:artist_info, artist_info)
|
||||
|> assign(:biography, build_biography(artist_info))
|
||||
|> put_toast(:info, gettext("Wikipedia data refreshed successfully"))}
|
||||
|
||||
{:error, reason} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_toast(
|
||||
:error,
|
||||
gettext("Error refreshing Wikipedia data") <> "," <> inspect(reason)
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
||||
def handle_event("refresh_artist_image", %{"id" => id}, socket) do
|
||||
case Artists.fetch_image(id) do
|
||||
{:ok, artist_info} ->
|
||||
@@ -171,6 +191,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
||||
|> assign(:current_section, :artists)
|
||||
|> assign(:artist, artist)
|
||||
|> assign(:artist_info, artist_info)
|
||||
|> assign(:biography, build_biography(artist_info))
|
||||
|> assign(:external_links, ArtistInfo.external_links(artist_info))
|
||||
|> assign(:country, ArtistInfo.country(artist_info))
|
||||
|> assign_async(:lastfm_artist_info, fn ->
|
||||
@@ -250,6 +271,20 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
||||
}
|
||||
end
|
||||
|
||||
defp build_biography(artist_info) do
|
||||
bio_html = ArtistInfo.wikipedia_bio(artist_info)
|
||||
|
||||
if bio_html do
|
||||
%{
|
||||
source: "Wikipedia",
|
||||
summary_html: ArtistInfo.wikipedia_summary(artist_info),
|
||||
bio_html: bio_html,
|
||||
url: ArtistInfo.wikipedia_url(artist_info),
|
||||
description: ArtistInfo.wikipedia_description(artist_info)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Bios start with text, then a link to read more on Last.fm, followed by a license text.
|
||||
# We split the bio at the read more link in order to render the license separately.
|
||||
defp render_bio(bio) do
|
||||
|
||||
Reference in New Issue
Block a user