Add LastFm.Scrobble abstraction

This commit is contained in:
Claudio Ortolina
2025-05-07 08:38:35 +01:00
parent fcdae8f925
commit 8477517e5c
3 changed files with 18 additions and 7 deletions
+5 -3
View File
@@ -1,5 +1,5 @@
defmodule LastFm do
alias LastFm.{API, Feed, Refresh}
alias LastFm.{API, Feed, Refresh, Scrobble}
def get_scrobbled_tracks, do: Feed.all_tracks()
@@ -47,10 +47,12 @@ defmodule LastFm do
API.get_session(token, last_fm_config)
end
def scrobble(tracks, session_key) do
def scrobble(scrobbles, session_key) do
last_fm_config = last_fm_config()
API.scrobble(tracks, session_key, last_fm_config)
scrobbles
|> Enum.map(&Scrobble.encode/1)
|> API.scrobble(session_key, last_fm_config)
end
def auth_url do
+9
View File
@@ -0,0 +1,9 @@
defmodule LastFm.Scrobble do
defstruct [:track, :artist, :timestamp, :album, :album_artist, :mbid]
def encode(scrobble) do
scrobble
|> Map.from_struct()
|> Map.reject(fn {_key, value} -> is_nil(value) end)
end
end