From 08da5bb2721f8bc0542306de325cfb44e5ff6da1 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sun, 15 Feb 2026 11:38:26 +0000 Subject: [PATCH] Fix parsing of record type from MB response --- lib/music_library/records/record.ex | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/music_library/records/record.ex b/lib/music_library/records/record.ex index c9d40cfb..28bcee77 100644 --- a/lib/music_library/records/record.ex +++ b/lib/music_library/records/record.ex @@ -229,7 +229,7 @@ defmodule MusicLibrary.Records.Record do "title" => release_group["title"], "artists" => artists_attrs, "release_date" => release_group["first-release-date"], - "type" => parse_subtype(release_group["primary-type"]), + "type" => parse_subtype(release_group["primary-type"], release_group["secondary-types"]), "genres" => Enum.map(release_group["genres"], fn g -> g["name"] end), "release_ids" => Enum.map(release_group["releases"], fn r -> r["id"] end), "cover_url" => "https://coverartarchive.org/release-group/#{musicbrainz_id}/front" @@ -250,12 +250,18 @@ defmodule MusicLibrary.Records.Record do end) end - defp parse_subtype("Album"), do: :album - defp parse_subtype("EP"), do: :ep - defp parse_subtype("Live"), do: :live - defp parse_subtype("Compilation"), do: :compilation - defp parse_subtype("Single"), do: :single - defp parse_subtype(_), do: :other + defp parse_subtype("Album", secondary_types), do: parse_secondary_types(secondary_types) + defp parse_subtype("EP", _secondary_types), do: :ep + defp parse_subtype("Single", _secondary_types), do: :single + defp parse_subtype(_primary_type, _secondary_types), do: :other + + defp parse_secondary_types(secondary_types) do + cond do + "Live" in secondary_types -> :live + "Compilation" in secondary_types -> :compilation + true -> :album + end + end @doc """ Format a release date in a conventional format.