diff --git a/lib/music_library/scrobble_activity.ex b/lib/music_library/scrobble_activity.ex index 69790acb..43ba971a 100644 --- a/lib/music_library/scrobble_activity.ex +++ b/lib/music_library/scrobble_activity.ex @@ -1,7 +1,11 @@ defmodule MusicLibrary.ScrobbleActivity do alias LastFm.Scrobble alias MusicBrainz.Release - alias MusicLibrary.{Artists, Collection, Wishlist} + alias MusicLibrary.{Artists, Collection, Secrets, Wishlist} + + def can_scrobble? do + Secrets.get("last_fm_session_key") !== nil + end def scrobble(release_with_tracks, opts) when is_list(opts) do case opts do @@ -26,7 +30,7 @@ defmodule MusicLibrary.ScrobbleActivity do end def scrobble(release_with_tracks, {:started_at, started_at}) do - session_key = MusicLibrary.Secrets.get!("last_fm_session_key").value + session_key = Secrets.get!("last_fm_session_key").value {scrobbles, _finished_at} = release_with_tracks diff --git a/lib/music_library/secrets.ex b/lib/music_library/secrets.ex index 5aa46246..59747296 100644 --- a/lib/music_library/secrets.ex +++ b/lib/music_library/secrets.ex @@ -11,4 +11,8 @@ defmodule MusicLibrary.Secrets do def get!(name) do Repo.get!(Secret, name) end + + def get(name) do + Repo.get(Secret, name) + end end diff --git a/lib/music_library_web/controllers/session_html/new.html.heex b/lib/music_library_web/controllers/session_html/new.html.heex index 6e8ba6e8..d539ae68 100644 --- a/lib/music_library_web/controllers/session_html/new.html.heex +++ b/lib/music_library_web/controllers/session_html/new.html.heex @@ -35,8 +35,5 @@ - - Connect to Last.fm - diff --git a/lib/music_library_web/live/collection_live/show.ex b/lib/music_library_web/live/collection_live/show.ex index 6da52ff2..1a3468f2 100644 --- a/lib/music_library_web/live/collection_live/show.ex +++ b/lib/music_library_web/live/collection_live/show.ex @@ -27,7 +27,10 @@ defmodule MusicLibraryWeb.CollectionLive.Show do Records.subscribe(record_id) end - {:ok, assign(socket, :release_with_tracks, nil)} + {:ok, + socket + |> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?()) + |> assign(:release_with_tracks, nil)} end @impl true diff --git a/lib/music_library_web/live/collection_live/show.html.heex b/lib/music_library_web/live/collection_live/show.html.heex index 1c61a0a9..21ba1cf3 100644 --- a/lib/music_library_web/live/collection_live/show.html.heex +++ b/lib/music_library_web/live/collection_live/show.html.heex @@ -282,8 +282,6 @@ >