Use fallback cover when not found

This commit is contained in:
Claudio Ortolina
2024-10-07 10:19:24 +01:00
parent be9dc37ed5
commit fa0be0d740
2 changed files with 10 additions and 0 deletions
@@ -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)
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB