Improve heuristics for extraction of Discogs ID
This commit is contained in:
@@ -13,10 +13,23 @@ defmodule MusicBrainz.Artist do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# MASSIVE ASSUMPTION: if there's more than one Discogs link,
|
||||||
|
# take the one with the lowest ID, as it's likely to be the main one.
|
||||||
def get_discogs_id(r) do
|
def get_discogs_id(r) do
|
||||||
Enum.find_value(r.relations, fn relation ->
|
candidates =
|
||||||
if relation.type == "discogs", do: parse_discogs_id(relation.url["resource"])
|
r.relations
|
||||||
end)
|
|> Enum.filter(fn relation ->
|
||||||
|
relation.type == "discogs"
|
||||||
|
end)
|
||||||
|
|> Enum.map(fn relation ->
|
||||||
|
parse_discogs_id(relation.url["resource"])
|
||||||
|
end)
|
||||||
|
|> Enum.sort()
|
||||||
|
|
||||||
|
case candidates do
|
||||||
|
[] -> nil
|
||||||
|
[id | _rest] -> id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def url(id) do
|
def url(id) do
|
||||||
@@ -32,6 +45,6 @@ defmodule MusicBrainz.Artist do
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp parse_discogs_id("https://www.discogs.com/artist/" <> id), do: id
|
defp parse_discogs_id("https://www.discogs.com/artist/" <> id), do: String.to_integer(id)
|
||||||
defp parse_discogs_id(_other), do: nil
|
defp parse_discogs_id(_other), do: nil
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user