From 80ec4336f62be4fd3e942af9a901eaf15b56643e Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 9 May 2025 11:27:47 +0100 Subject: [PATCH] Account for artist info areas having iso-3166-2-codes --- lib/music_library/records/artist_info.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/music_library/records/artist_info.ex b/lib/music_library/records/artist_info.ex index 04016ef7..d5651fb9 100644 --- a/lib/music_library/records/artist_info.ex +++ b/lib/music_library/records/artist_info.ex @@ -30,8 +30,12 @@ defmodule MusicLibrary.Records.ArtistInfo do def country(artist_info) do %{"area" => area} = artist_info.musicbrainz_data - [country_code | _rest] = area["iso-3166-1-codes"] - %{name: area["name"], code: country_code} + [country_code | _rest] = area["iso-3166-1-codes"] || area["iso-3166-2-codes"] + %{name: area["name"], code: keep_alpha_2(country_code)} + end + + defp keep_alpha_2(country_code) do + String.slice(country_code, 0..1) end def generate_image_hash(%__MODULE__{image_data: image_data} = artist_info) do