Use stored scrobbled tracks

This commit is contained in:
Claudio Ortolina
2025-05-31 21:36:05 +01:00
parent 32956ca593
commit 1703f1cf70
5 changed files with 39 additions and 46 deletions
+1 -22
View File
@@ -1,28 +1,7 @@
defmodule LastFm.Import do
@insertable_fields [
:musicbrainz_id,
:title,
:artist,
:album,
:cover_url,
:scrobbled_at_uts,
:scrobbled_at_label,
:last_fm_data
]
def batch(opts) do
with {:ok, tracks} <- LastFm.get_tracks(opts) do
track_params =
tracks
|> Enum.map(fn t -> Map.take(t, @insertable_fields) end)
|> Enum.map(&Map.to_list/1)
# HACK: if two tracks happen to have the exact same scrobbled_at_uts,
# we move it by a sec.
MusicLibrary.Repo.insert_all(LastFm.Track, track_params,
on_conflict: :nothing,
conflict_target: [:scrobbled_at_uts, :title]
)
LastFm.Feed.update(tracks)
end
end
end