Don't apply fallback cover when refreshing it
So that we don't accidentally override a user-uploaded cover with the fallback one.
This commit is contained in:
@@ -405,10 +405,6 @@ defmodule 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.
|
||||||
"""
|
"""
|
||||||
@@ -427,7 +423,7 @@ defmodule MusicBrainz.APIImpl do
|
|||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
Logger.error("Failed to fetch cover art for #{url}, reason: #{inspect(reason)}")
|
Logger.error("Failed to fetch cover art for #{url}, reason: #{inspect(reason)}")
|
||||||
|
|
||||||
{:ok, @fallback_cover}
|
{:error, :cover_not_available}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ defmodule MusicLibrary.Records do
|
|||||||
with format = Keyword.get(opts, :format, "cd"),
|
with format = Keyword.get(opts, :format, "cd"),
|
||||||
purchased_at = Keyword.get(opts, :purchased_at),
|
purchased_at = Keyword.get(opts, :purchased_at),
|
||||||
{:ok, release_group} <- musicbrainz().get_release_group(musicbrainz_id),
|
{:ok, release_group} <- musicbrainz().get_release_group(musicbrainz_id),
|
||||||
{:ok, cover_data} <- musicbrainz().get_cover_art({:musicbrainz_id, musicbrainz_id}),
|
{:ok, cover_data} <- get_cover_art_or_default(musicbrainz_id),
|
||||||
record_attrs =
|
record_attrs =
|
||||||
build_record_attrs(release_group, %{
|
build_record_attrs(release_group, %{
|
||||||
"cover_data" => cover_data,
|
"cover_data" => cover_data,
|
||||||
@@ -124,6 +124,13 @@ defmodule MusicLibrary.Records do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_cover_art_or_default(musicbrainz_id) do
|
||||||
|
case musicbrainz().get_cover_art({:musicbrainz_id, musicbrainz_id}) do
|
||||||
|
{:error, :cover_not_available} -> {:ok, Record.fallback_cover_data()}
|
||||||
|
success -> success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def refresh_cover(record) do
|
def refresh_cover(record) do
|
||||||
with {:ok, cover_data} <- musicbrainz().get_cover_art({:url, record.cover_url}) do
|
with {:ok, cover_data} <- musicbrainz().get_cover_art({:url, record.cover_url}) do
|
||||||
{:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, 600)
|
{:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, 600)
|
||||||
|
|||||||
@@ -137,6 +137,12 @@ defmodule MusicLibrary.Records.Record do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@fallback_cover_data :code.priv_dir(:music_library)
|
||||||
|
|> Path.join("/cover-not-found.jpg")
|
||||||
|
|> File.read!()
|
||||||
|
|
||||||
|
def fallback_cover_data, do: @fallback_cover_data
|
||||||
|
|
||||||
defp extract_included_release_group_ids(musicbrainz_data) do
|
defp extract_included_release_group_ids(musicbrainz_data) do
|
||||||
musicbrainz_data
|
musicbrainz_data
|
||||||
|> Map.get("relations", [])
|
|> Map.get("relations", [])
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
socket
|
socket
|
||||||
|> put_flash(
|
|> put_flash(
|
||||||
:error,
|
:error,
|
||||||
gettext("Error refreshing MusicBrainz data") <> "," <> inspect(reason)
|
gettext("Error refreshing cover") <> "," <> inspect(reason)
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
|
|||||||
socket
|
socket
|
||||||
|> put_flash(
|
|> put_flash(
|
||||||
:error,
|
:error,
|
||||||
gettext("Error refreshing MusicBrainz data") <> "," <> inspect(reason)
|
gettext("Error refreshing Cover") <> "," <> inspect(reason)
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -398,9 +398,7 @@ msgid "Includes"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/collection_live/show.ex:61
|
#: lib/music_library_web/live/collection_live/show.ex:61
|
||||||
#: lib/music_library_web/live/collection_live/show.ex:81
|
|
||||||
#: lib/music_library_web/live/wishlist_live/show.ex:59
|
#: lib/music_library_web/live/wishlist_live/show.ex:59
|
||||||
#: lib/music_library_web/live/wishlist_live/show.ex:79
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Error refreshing MusicBrainz data"
|
msgid "Error refreshing MusicBrainz data"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -441,3 +439,13 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Refresh"
|
msgid "Refresh"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/wishlist_live/show.ex:79
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Error refreshing Cover"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/collection_live/show.ex:81
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Error refreshing cover"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user