Use fallback cover when not found
This commit is contained in:
@@ -217,6 +217,10 @@ defmodule MusicLibrary.Records.MusicBrainz.APIImpl do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@fallback_cover File.read!(
|
||||||
|
(:code.priv_dir(:music_library) |> to_string()) <> "/cover-not-found.jpg"
|
||||||
|
)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Uses the [cover art](https://musicbrainz.org/doc/Cover_Art_Archive/API) endpoint with the release group id to get the cover image.
|
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),
|
with {:ok, cover_data} <- blob_get(url),
|
||||||
{:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, 400) do
|
{:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, 400) do
|
||||||
Vix.Vips.Image.write_to_buffer(thumb, ".jpg")
|
Vix.Vips.Image.write_to_buffer(thumb, ".jpg")
|
||||||
|
else
|
||||||
|
{:error, :not_found} -> {:ok, @fallback_cover}
|
||||||
|
error -> error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -266,6 +273,9 @@ defmodule MusicLibrary.Records.MusicBrainz.APIImpl do
|
|||||||
Logger.debug("Following redirect to #{location}")
|
Logger.debug("Following redirect to #{location}")
|
||||||
blob_get(location)
|
blob_get(location)
|
||||||
|
|
||||||
|
{:ok, response} when response.status == 404 ->
|
||||||
|
{:error, :not_found}
|
||||||
|
|
||||||
other ->
|
other ->
|
||||||
msg = "Failed to fetch data from #{url}, reason: #{inspect(other)}"
|
msg = "Failed to fetch data from #{url}, reason: #{inspect(other)}"
|
||||||
Logger.error(msg)
|
Logger.error(msg)
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Reference in New Issue
Block a user