From 7411177e7df3b41abebcfa789fb66c5e2fc45f2c Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 25 Mar 2024 20:40:09 -0700 Subject: [PATCH] Added description to source (#124) --- .../metadata/source_metadata_storage_worker.ex | 2 ++ lib/pinchflat/sources/source.ex | 2 ++ ...20240325222846_add_description_to_source.exs | 9 +++++++++ .../source_metadata_storage_worker_test.exs | 17 +++++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 priv/repo/migrations/20240325222846_add_description_to_source.exs diff --git a/lib/pinchflat/metadata/source_metadata_storage_worker.ex b/lib/pinchflat/metadata/source_metadata_storage_worker.ex index a0ce7f5..eda6297 100644 --- a/lib/pinchflat/metadata/source_metadata_storage_worker.ex +++ b/lib/pinchflat/metadata/source_metadata_storage_worker.ex @@ -32,6 +32,7 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do @doc """ Fetches and stores various forms of metadata for a source: + - Attributes like `description` - JSON metadata for internal use - The series directory for the source - The NFO file for the source (if specified) @@ -59,6 +60,7 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do %{ series_directory: series_directory, nfo_filepath: store_source_nfo(source, series_directory, source_metadata), + description: source_metadata["description"], metadata: Map.merge(%{metadata_filepath: source_metadata_filepath}, metadata_image_attrs) }, source_image_attrs diff --git a/lib/pinchflat/sources/source.ex b/lib/pinchflat/sources/source.ex index 1de247c..d2d10c8 100644 --- a/lib/pinchflat/sources/source.ex +++ b/lib/pinchflat/sources/source.ex @@ -17,6 +17,7 @@ defmodule Pinchflat.Sources.Source do collection_id collection_type custom_name + description nfo_filepath poster_filepath fanart_filepath @@ -55,6 +56,7 @@ defmodule Pinchflat.Sources.Source do schema "sources" do field :custom_name, :string + field :description, :string field :collection_name, :string field :collection_id, :string field :collection_type, Ecto.Enum, values: [:channel, :playlist] diff --git a/priv/repo/migrations/20240325222846_add_description_to_source.exs b/priv/repo/migrations/20240325222846_add_description_to_source.exs new file mode 100644 index 0000000..583abd8 --- /dev/null +++ b/priv/repo/migrations/20240325222846_add_description_to_source.exs @@ -0,0 +1,9 @@ +defmodule Pinchflat.Repo.Migrations.AddDescriptionToSource do + use Ecto.Migration + + def change do + alter table(:sources) do + add :description, :string + end + end +end diff --git a/test/pinchflat/metadata/source_metadata_storage_worker_test.exs b/test/pinchflat/metadata/source_metadata_storage_worker_test.exs index 48befbc..878f8fd 100644 --- a/test/pinchflat/metadata/source_metadata_storage_worker_test.exs +++ b/test/pinchflat/metadata/source_metadata_storage_worker_test.exs @@ -50,6 +50,23 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do end end + describe "perform/1 when testing attribute updates" do + test "the source description is saved" do + stub(YtDlpRunnerMock, :run, fn + _url, _opts, ot when ot == @source_details_ot -> {:ok, source_details_return_fixture()} + _url, _opts, ot when ot == @metadata_ot -> {:ok, render_metadata(:channel_source_metadata)} + end) + + source = source_fixture() + + refute source.description + perform_job(SourceMetadataStorageWorker, %{id: source.id}) + source = Repo.preload(Repo.reload(source), :metadata) + + assert source.description == "This is a test file for Pinchflat" + end + end + describe "perform/1 when testing metadata storage" do test "sets metadata location for source" do stub(YtDlpRunnerMock, :run, fn