Scrobble entire release from wishlist show page

This commit is contained in:
Claudio Ortolina
2026-05-29 08:22:14 +03:00
parent 33474c1472
commit f4648ce5d9
3 changed files with 62 additions and 1 deletions
@@ -1,6 +1,8 @@
defmodule MusicLibraryWeb.WishlistLive.Show do defmodule MusicLibraryWeb.WishlistLive.Show do
use MusicLibraryWeb, :live_view use MusicLibraryWeb, :live_view
require Logger
import MusicLibraryWeb.RecordComponents, import MusicLibraryWeb.RecordComponents,
only: [ only: [
artist_links: 1, artist_links: 1,
@@ -18,7 +20,8 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
alias MusicLibrary.Chats alias MusicLibrary.Chats
alias MusicLibrary.OnlineStoreTemplates alias MusicLibrary.OnlineStoreTemplates
alias MusicLibrary.{Records, RecordSets} alias MusicLibrary.{Records, RecordSets, ScrobbleActivity}
alias MusicLibraryWeb.ErrorMessages
alias MusicLibraryWeb.LiveHelpers.RecordActions alias MusicLibraryWeb.LiveHelpers.RecordActions
@impl true @impl true
@@ -45,6 +48,19 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
</h1> </h1>
<div class="min-w-12"> <div class="min-w-12">
<.button_group> <.button_group>
<.button
:if={@can_scrobble? and @record.selected_release_id}
variant="soft"
phx-click="scrobble_release"
>
<span class="sr-only">{gettext("Scrobble release")}</span>
<.icon
name="hero-play"
class="icon"
aria-hidden="true"
data-slot="icon"
/>
</.button>
<.button <.button
variant="soft" variant="soft"
phx-click={MusicLibraryWeb.Components.Chat.open("record-chat-sheet")} phx-click={MusicLibraryWeb.Components.Chat.open("record-chat-sheet")}
@@ -319,6 +335,7 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
{:ok, {:ok,
socket socket
|> assign(current_section: :wishlist) |> assign(current_section: :wishlist)
|> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())
|> assign(:current_date, current_date)} |> assign(:current_date, current_date)}
end end
@@ -380,6 +397,44 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
RecordActions.extract_colors(socket) RecordActions.extract_colors(socket)
end end
def handle_event("scrobble_release", _params, socket) do
record = socket.assigns.record
{:noreply,
start_async(socket, :scrobble_release, fn ->
with {:ok, release} <- MusicBrainz.get_release(record.selected_release_id) do
release_with_tracks = MusicBrainz.Release.from_api_response(release)
ScrobbleActivity.scrobble_release(release_with_tracks, :finished_at, DateTime.utc_now())
end
end)}
end
@impl true
def handle_async(:scrobble_release, {:ok, {:ok, _result}}, socket) do
{:noreply, put_toast(socket, :info, gettext("Release scrobbled successfully"))}
end
def handle_async(:scrobble_release, {:ok, {:error, reason}}, socket) do
{:noreply,
put_toast(
socket,
:error,
gettext("Error scrobbling release") <> ": " <> ErrorMessages.friendly_message(reason)
)}
end
def handle_async(:scrobble_release, {:exit, reason}, socket) do
Logger.error("Scrobble release failed: #{inspect(reason)}")
{:noreply,
put_toast(
socket,
:error,
gettext("Error scrobbling release") <> ": " <> ErrorMessages.friendly_message(reason)
)}
end
@impl true @impl true
def handle_info({MusicLibraryWeb.Components.RecordForm, {:saved, record}}, socket) do def handle_info({MusicLibraryWeb.Components.RecordForm, {:saved, record}}, socket) do
{:noreply, {:noreply,
+3
View File
@@ -640,12 +640,14 @@ msgstr ""
#: lib/music_library_web/components/release.ex #: lib/music_library_web/components/release.ex
#: lib/music_library_web/live/collection_live/show.ex #: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Error scrobbling release" msgid "Error scrobbling release"
msgstr "" msgstr ""
#: lib/music_library_web/components/release.ex #: lib/music_library_web/components/release.ex
#: lib/music_library_web/live/collection_live/show.ex #: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Release scrobbled successfully" msgid "Release scrobbled successfully"
msgstr "" msgstr ""
@@ -662,6 +664,7 @@ msgstr ""
#: lib/music_library_web/components/release.ex #: lib/music_library_web/components/release.ex
#: lib/music_library_web/live/collection_live/show.ex #: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Scrobble release" msgid "Scrobble release"
msgstr "" msgstr ""
+3
View File
@@ -640,12 +640,14 @@ msgstr ""
#: lib/music_library_web/components/release.ex #: lib/music_library_web/components/release.ex
#: lib/music_library_web/live/collection_live/show.ex #: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Error scrobbling release" msgid "Error scrobbling release"
msgstr "" msgstr ""
#: lib/music_library_web/components/release.ex #: lib/music_library_web/components/release.ex
#: lib/music_library_web/live/collection_live/show.ex #: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Release scrobbled successfully" msgid "Release scrobbled successfully"
msgstr "" msgstr ""
@@ -662,6 +664,7 @@ msgstr ""
#: lib/music_library_web/components/release.ex #: lib/music_library_web/components/release.ex
#: lib/music_library_web/live/collection_live/show.ex #: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Scrobble release" msgid "Scrobble release"
msgstr "" msgstr ""