From 533fe8a8c4c1a16af4d6bc3087594d5d30fc67c2 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 13 May 2026 20:14:01 +0100 Subject: [PATCH] Streamline function implementation (no double negative) --- lib/music_library/records/enrichment.ex | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/music_library/records/enrichment.ex b/lib/music_library/records/enrichment.ex index 04bfcf35..21376c52 100644 --- a/lib/music_library/records/enrichment.ex +++ b/lib/music_library/records/enrichment.ex @@ -81,12 +81,9 @@ defmodule MusicLibrary.Records.Enrichment do @spec extract_colors(Record.t()) :: {:ok, Record.t()} | {:error, term()} def extract_colors(record) do - with asset when not is_nil(asset) <- Assets.get(record.cover_hash), + with {:ok, asset} <- get_asset(record.cover_hash), {:ok, colors} <- @color_extractor.extract_dominant_colors(asset.content) do Records.update_record(record, %{dominant_colors: colors}) - else - nil -> {:error, :asset_not_found} - error -> error end end @@ -125,4 +122,12 @@ defmodule MusicLibrary.Records.Enrichment do defp record_meta(record) do %{title: record.title, artists: Enum.map(record.artists, & &1.name)} end + + defp get_asset(cover_hash) do + if asset = Assets.get(cover_hash) do + {:ok, asset} + else + {:error, :asset_not_found} + end + end end