Add function to backfill missing data in scrobbled tracks
This commit is contained in:
@@ -31,6 +31,16 @@ defmodule MusicLibrary.Artists do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def name_id_pairs(names) do
|
||||||
|
q =
|
||||||
|
from ar in ArtistRecord,
|
||||||
|
distinct: true,
|
||||||
|
where: fragment("artist ->> '$.name'") in ^names,
|
||||||
|
select: {fragment("artist ->> '$.name'"), ar.musicbrainz_id}
|
||||||
|
|
||||||
|
Repo.all(q)
|
||||||
|
end
|
||||||
|
|
||||||
def get_all_artist_ids do
|
def get_all_artist_ids do
|
||||||
q = from ar in ArtistRecord, distinct: true, select: ar.musicbrainz_id
|
q = from ar in ArtistRecord, distinct: true, select: ar.musicbrainz_id
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
defmodule MusicLibrary.ScrobbleActivity.Backfill do
|
||||||
|
alias MusicLibrary.Artists
|
||||||
|
alias MusicLibrary.Repo
|
||||||
|
|
||||||
|
@allowed_artists [
|
||||||
|
"IQ",
|
||||||
|
"Riverside",
|
||||||
|
"Airbag",
|
||||||
|
"Arena",
|
||||||
|
"Fish",
|
||||||
|
"Marillion",
|
||||||
|
"Porcupine Tree",
|
||||||
|
"Steven Wilson",
|
||||||
|
"Gazpacho",
|
||||||
|
"Sylvan",
|
||||||
|
"Dream Theater",
|
||||||
|
"Pink Floyd",
|
||||||
|
"Muse",
|
||||||
|
"Opeth"
|
||||||
|
]
|
||||||
|
|
||||||
|
def fill_missing_artist_ids do
|
||||||
|
name_id_pairs = Artists.name_id_pairs(@allowed_artists)
|
||||||
|
|
||||||
|
Enum.each(name_id_pairs, fn {name, id} ->
|
||||||
|
Repo.query(
|
||||||
|
"""
|
||||||
|
UPDATE scrobbled_tracks
|
||||||
|
SET artist = json_set(artist, '$.musicbrainz_id', ?)
|
||||||
|
WHERE artist ->> '$.name' == ?;
|
||||||
|
""",
|
||||||
|
[id, name]
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user