Streamline batch module, removing obsolete functions

This commit is contained in:
Claudio Ortolina
2024-11-10 14:27:25 +00:00
parent 5d5f9babe1
commit 05d1d648b1
5 changed files with 22 additions and 149 deletions
+12 -1
View File
@@ -96,7 +96,7 @@ defmodule MusicLibrary.Records do
with format = Keyword.get(opts, :format, "cd"),
purchased_at = Keyword.get(opts, :purchased_at),
{:ok, release_group} <- musicbrainz().get_release_group(musicbrainz_id),
{:ok, cover_data} <- musicbrainz().get_cover_art(musicbrainz_id),
{:ok, cover_data} <- musicbrainz().get_cover_art({:musicbrainz_id, musicbrainz_id}),
record_params = build_record_params(release_group, cover_data, format, purchased_at) do
create_record(record_params)
else
@@ -104,6 +104,17 @@ defmodule MusicLibrary.Records do
end
end
def refresh_cover(record) do
with {:ok, cover_data} <- musicbrainz().get_cover_art({:url, record.cover_url}) do
{:ok, thumb} = Vix.Vips.Operation.thumbnail_buffer(cover_data, 400)
{:ok, thumb_data} = Vix.Vips.Image.write_to_buffer(thumb, ".jpg")
record
|> Record.add_cover_data(thumb_data)
|> Repo.update!()
end
end
defp build_record_params(release_group, cover_data, format, purchased_at) do
musicbrainz_id = release_group["id"]