Link Last.fm account from tracks
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
defmodule MusicLibrary.ScrobbleActivity do
|
defmodule MusicLibrary.ScrobbleActivity do
|
||||||
alias LastFm.Scrobble
|
alias LastFm.Scrobble
|
||||||
alias MusicBrainz.Release
|
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
|
def scrobble(release_with_tracks, opts) when is_list(opts) do
|
||||||
case opts do
|
case opts do
|
||||||
@@ -26,7 +30,7 @@ defmodule MusicLibrary.ScrobbleActivity do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def scrobble(release_with_tracks, {:started_at, started_at}) do
|
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} =
|
{scrobbles, _finished_at} =
|
||||||
release_with_tracks
|
release_with_tracks
|
||||||
|
|||||||
@@ -11,4 +11,8 @@ defmodule MusicLibrary.Secrets do
|
|||||||
def get!(name) do
|
def get!(name) do
|
||||||
Repo.get!(Secret, name)
|
Repo.get!(Secret, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get(name) do
|
||||||
|
Repo.get(Secret, name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,8 +35,5 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</.form>
|
</.form>
|
||||||
<a href={LastFm.auth_url()} class="flex items-center justify-center">
|
|
||||||
Connect to Last.fm
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
Records.subscribe(record_id)
|
Records.subscribe(record_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, assign(socket, :release_with_tracks, nil)}
|
{:ok,
|
||||||
|
socket
|
||||||
|
|> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())
|
||||||
|
|> assign(:release_with_tracks, nil)}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|||||||
@@ -282,8 +282,6 @@
|
|||||||
>
|
>
|
||||||
<h3 class="text-lg font-semibold text-zinc-700 dark:text-zinc-300">{gettext("Tracks")}</h3>
|
<h3 class="text-lg font-semibold text-zinc-700 dark:text-zinc-300">{gettext("Tracks")}</h3>
|
||||||
|
|
||||||
<.button phx-click="scrobble_release">{gettext("Scrobble to Last.fm")}</.button>
|
|
||||||
|
|
||||||
<div :if={@release_with_tracks} class="space-y-4 mt-4">
|
<div :if={@release_with_tracks} class="space-y-4 mt-4">
|
||||||
<.async_result :let={release_with_tracks} assign={@release_with_tracks}>
|
<.async_result :let={release_with_tracks} assign={@release_with_tracks}>
|
||||||
<:loading>
|
<:loading>
|
||||||
@@ -335,6 +333,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</.async_result>
|
</.async_result>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<.button :if={@can_scrobble?} phx-click="scrobble_release">
|
||||||
|
{gettext("Scrobble to Last.fm")}
|
||||||
|
</.button>
|
||||||
|
<a
|
||||||
|
:if={!@can_scrobble?}
|
||||||
|
class={[
|
||||||
|
"relative inline-flex items-center rounded-md",
|
||||||
|
"mt-4 px-3 py-2 text-xs sm:text-sm font-semibold",
|
||||||
|
"bg-zinc-900 hover:bg-zinc-800 dark:bg-zinc-100 dark:hover:bg-zinc-200",
|
||||||
|
"disabled:bg-zinc-300 dark:disabled:bg-zinc-300 disabled:active:text-white",
|
||||||
|
"text-white active:text-white/80 dark:text-zinc-900 dark:active:text-zinc-900/80",
|
||||||
|
"focus-visible:outline focus-visible:outline-offset-2 focus-visible:outline-zinc-600"
|
||||||
|
]}
|
||||||
|
href={LastFm.auth_url()}
|
||||||
|
>
|
||||||
|
{gettext("Connect your Last.fm account")}
|
||||||
|
</a>
|
||||||
</Fluxon.Components.Sheet.sheet>
|
</Fluxon.Components.Sheet.sheet>
|
||||||
|
|
||||||
<.modal
|
<.modal
|
||||||
|
|||||||
@@ -799,3 +799,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Scrobble to Last.fm"
|
msgid "Scrobble to Last.fm"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/collection_live/show.html.heex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Connect your Last.fm account"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user