diff --git a/lib/last_fm.ex b/lib/last_fm.ex index 5f6e460d..e562af23 100644 --- a/lib/last_fm.ex +++ b/lib/last_fm.ex @@ -76,5 +76,11 @@ defmodule LastFm do "https://www.last.fm/api/auth/?api_key=" <> last_fm_config.api_key end + @last_fm_fallback_cover_url "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png" + + def fallback_cover?(cover_url) do + cover_url == @last_fm_fallback_cover_url + end + defp last_fm_config, do: LastFm.Config.resolve(:music_library) end diff --git a/lib/music_library_web/live/stats_live/index.ex b/lib/music_library_web/live/stats_live/index.ex index d1164030..9367610b 100644 --- a/lib/music_library_web/live/stats_live/index.ex +++ b/lib/music_library_web/live/stats_live/index.ex @@ -150,10 +150,8 @@ defmodule MusicLibraryWeb.StatsLive.Index do |> DateTime.to_iso8601() end - @last_fm_fallback_cover_url "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png" - defp track_or_album_cover_url(track_or_album, cover_hash) do - if track_or_album.cover_url == @last_fm_fallback_cover_url do + if LastFm.fallback_cover?(track_or_album.cover_url) do payload = Transform.new(hash: cover_hash, width: 96) |> Transform.encode!() diff --git a/lib/music_library_web/live/stats_live/top_albums.ex b/lib/music_library_web/live/stats_live/top_albums.ex index a33d415a..58227c67 100644 --- a/lib/music_library_web/live/stats_live/top_albums.ex +++ b/lib/music_library_web/live/stats_live/top_albums.ex @@ -191,10 +191,8 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbums do end end - @last_fm_fallback_cover_url "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png" - defp cover_url(album) do - if album.cover_url == @last_fm_fallback_cover_url do + if LastFm.fallback_cover?(album.cover_url) do payload = Transform.new(hash: album.cover_hash, width: 96) |> Transform.encode!()