Use stored scrobbled tracks
This commit is contained in:
+1
-22
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user