From 0d77fdc031450ff62c9776f995628baf026acdb3 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 25 Jan 2025 08:50:46 +0000 Subject: [PATCH] Display badge when an artist is touring --- lib/last_fm/artist.ex | 8 +++++--- .../live/artist_live/show.html.heex | 1 + priv/gettext/default.pot | 15 ++++++++++----- test/last_fm/artist_test.exs | 3 ++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/last_fm/artist.ex b/lib/last_fm/artist.ex index 5b0f036b..e3083fd5 100644 --- a/lib/last_fm/artist.ex +++ b/lib/last_fm/artist.ex @@ -1,13 +1,14 @@ defmodule LastFm.Artist do @enforce_keys [:musicbrainz_id, :name] - defstruct [:musicbrainz_id, :name, :bio, :image, :play_count] + defstruct [:musicbrainz_id, :name, :bio, :image, :play_count, :on_tour] @type t :: %__MODULE__{ musicbrainz_id: String.t(), name: String.t(), bio: String.t(), image: String.t(), - play_count: non_neg_integer() + play_count: non_neg_integer(), + on_tour: boolean() } def from_api_response(api_response) do @@ -16,7 +17,8 @@ defmodule LastFm.Artist do name: api_response["name"], bio: api_response["bio"]["content"] || "", image: get_image(api_response), - play_count: get_play_count(api_response) + play_count: get_play_count(api_response), + on_tour: api_response["ontour"] == "1" } 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 01dcccca..70c5b499 100644 --- a/lib/music_library_web/live/artist_live/show.html.heex +++ b/lib/music_library_web/live/artist_live/show.html.heex @@ -28,6 +28,7 @@ {gettext("Number of scrobbles")} + <.round_badge :if={artist_info.on_tour} text={gettext("On Tour")} /> <.round_badge text={artist_info.play_count} /> diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 1dd4bb26..0a2005c9 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -30,7 +30,7 @@ msgid "Choose a value" msgstr "" #: lib/music_library_web/components/layouts/app.html.heex:14 -#: lib/music_library_web/live/artist_live/show.html.heex:64 +#: lib/music_library_web/live/artist_live/show.html.heex:65 #: lib/music_library_web/live/collection_live/index.ex:143 #: lib/music_library_web/live/collection_live/show.ex:115 #: lib/music_library_web/live/collection_live/show.ex:132 @@ -306,7 +306,7 @@ msgid "Welcome to your Music Library" msgstr "" #: lib/music_library_web/components/layouts/app.html.heex:20 -#: lib/music_library_web/live/artist_live/show.html.heex:73 +#: lib/music_library_web/live/artist_live/show.html.heex:74 #: lib/music_library_web/live/wishlist_live/index.ex:154 #: lib/music_library_web/live/wishlist_live/show.ex:130 #, elixir-autogen, elixir-format @@ -443,12 +443,12 @@ msgstr "" msgid "Number of scrobbles" msgstr "" -#: lib/music_library_web/live/artist_live/show.html.heex:57 +#: lib/music_library_web/live/artist_live/show.html.heex:58 #, elixir-autogen, elixir-format msgid "Biography" msgstr "" -#: lib/music_library_web/live/artist_live/show.html.heex:39 +#: lib/music_library_web/live/artist_live/show.html.heex:40 #, elixir-autogen, elixir-format msgid "Loading biography" msgstr "" @@ -493,7 +493,7 @@ msgstr "" msgid "Records" msgstr "" -#: lib/music_library_web/live/artist_live/show.html.heex:50 +#: lib/music_library_web/live/artist_live/show.html.heex:51 #, elixir-autogen, elixir-format msgid "Error loading biography" msgstr "" @@ -517,3 +517,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Number of records" msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex:31 +#, elixir-autogen, elixir-format +msgid "On Tour" +msgstr "" diff --git a/test/last_fm/artist_test.exs b/test/last_fm/artist_test.exs index 92152c83..deb5cd1c 100644 --- a/test/last_fm/artist_test.exs +++ b/test/last_fm/artist_test.exs @@ -18,7 +18,8 @@ defmodule LastFm.ArtistTest do "Steven Wilson (born Steven John Wilson on November 3, 1967, in Hemel Hempstead, Hertfordshire, England) is an English musician, singer, songwriter and record producer, most closely associated with the progressive rock genre. Currently a solo artist, he became known as the founder, lead guitarist, lead vocalist and songwriter of the British rock band Porcupine Tree, as well as being a member of several other bands.\n\nWilson is self-taught as a producer, audio engineer, multi-instrumentalist and singer-songwriter. Under his own name, he has released the albums Insurgentes (2008), Grace for Drowning (2011), The Raven That Refused to Sing (and Other Stories) (2013), Hand. Cannot. Erase. (2015), To the Bone (2017), and The Future Bites (2021). He also released a EP, 4 ½ (2016), as well as a series of singles titled Cover Version (released online between 2003 and 2010; released worldwide as a compilation in 2014). His other solo projects can also be found attributed to monikers of his, such as Bass Communion and Incredible Expanding Mindfuck.\n\nHe is perhaps best known as the frontman for progressive rock band, Porcupine Tree, for whom he was the sole member during the 1980s and early 1990s. His projects are numerous however, including collaboration with Aviv Geffen as Blackfield; a long-running partnership with Tim Bowness, known as No-Man; teaming up with Dirk Serries in Continuum; as well as a joint album with Opeth's frontman, Mikael Åkerfeldt in Storm Corrosion.\n\n\nWilson employs synthesizers and programmed music along with live instruments to create a unique atmosphere for each song he works on, including otherwise-simple pop tunes. In addition to his prolific musical output, Steven has crafted a reputation for the high production quality of his music, and has undertaken production duties with such high-profile artists as Opeth, Dream Theater, Jim Matheos of Fates Warning, Anathema, Orphaned Land, Marillion, Fish, Pendulum, Yoko Ono, and friend Robert Fripp. He is also part way through remixing the albums of King Crimson and other classic artists' back catalogues into surround sound and new stereo mixes. Read more on Last.fm. User-contributed text is available under the Creative Commons By-SA License; additional terms may apply.", image: "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png", - play_count: 123 + play_count: 123, + on_tour: false } == LastFm.Artist.from_api_response(api_response) end