diff --git a/lib/music_library/records/music_brainz/api_impl.ex b/lib/music_library/records/music_brainz/api_impl.ex index 504cc476..503b02b0 100644 --- a/lib/music_library/records/music_brainz/api_impl.ex +++ b/lib/music_library/records/music_brainz/api_impl.ex @@ -217,6 +217,10 @@ defmodule MusicLibrary.Records.MusicBrainz.APIImpl do end end + @fallback_cover File.read!( + (:code.priv_dir(:music_library) |> to_string()) <> "/cover-not-found.jpg" + ) + @doc """ Uses the [cover art](https://musicbrainz.org/doc/Cover_Art_Archive/API) endpoint with the release group id to get the cover image. """ @@ -227,6 +231,9 @@ defmodule MusicLibrary.Records.MusicBrainz.APIImpl do with {:ok, cover_data} <- blob_get(url), {:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, 400) do Vix.Vips.Image.write_to_buffer(thumb, ".jpg") + else + {:error, :not_found} -> {:ok, @fallback_cover} + error -> error end end @@ -266,6 +273,9 @@ defmodule MusicLibrary.Records.MusicBrainz.APIImpl do Logger.debug("Following redirect to #{location}") blob_get(location) + {:ok, response} when response.status == 404 -> + {:error, :not_found} + other -> msg = "Failed to fetch data from #{url}, reason: #{inspect(other)}" Logger.error(msg) diff --git a/priv/cover-not-found.jpg b/priv/cover-not-found.jpg new file mode 100644 index 00000000..c60603e9 Binary files /dev/null and b/priv/cover-not-found.jpg differ