diff --git a/lib/pinchflat/media.ex b/lib/pinchflat/media.ex index 0ec21d1..c9b0371 100644 --- a/lib/pinchflat/media.ex +++ b/lib/pinchflat/media.ex @@ -19,14 +19,14 @@ defmodule Pinchflat.Media do @doc """ Returns a list of pending media_items for a given channel, where - pending means the `video_filepath` is `nil`. + pending means the `media_filepath` is `nil`. Returns [%MediaItem{}, ...]. """ def list_pending_media_items_for(%Channel{} = channel) do from( m in MediaItem, - where: m.channel_id == ^channel.id and is_nil(m.video_filepath) + where: m.channel_id == ^channel.id and is_nil(m.media_filepath) ) |> Repo.all() end diff --git a/lib/pinchflat/media/media_item.ex b/lib/pinchflat/media/media_item.ex index baa3d7e..9db15d3 100644 --- a/lib/pinchflat/media/media_item.ex +++ b/lib/pinchflat/media/media_item.ex @@ -11,12 +11,12 @@ defmodule Pinchflat.Media.MediaItem do alias Pinchflat.Media.MediaMetadata @required_fields ~w(media_id channel_id)a - @allowed_fields ~w(title media_id video_filepath channel_id subtitle_filepaths)a + @allowed_fields ~w(title media_id media_filepath channel_id subtitle_filepaths)a schema "media_items" do field :title, :string field :media_id, :string - field :video_filepath, :string + field :media_filepath, :string # This is an array of [iso-2 language, filepath] pairs. Probably could # be an associated record, but I don't see the benefit right now. # Will very likely revisit because I can't leave well-enough alone. diff --git a/lib/pinchflat/media_client/backends/yt_dlp/metadata_parser.ex b/lib/pinchflat/media_client/backends/yt_dlp/metadata_parser.ex index 4fc3104..e2cd2b3 100644 --- a/lib/pinchflat/media_client/backends/yt_dlp/metadata_parser.ex +++ b/lib/pinchflat/media_client/backends/yt_dlp/metadata_parser.ex @@ -30,7 +30,7 @@ defmodule Pinchflat.MediaClient.Backends.YtDlp.MetadataParser do defp parse_media_metadata(metadata) do %{ title: metadata["title"], - video_filepath: metadata["filepath"] + media_filepath: metadata["filepath"] } end diff --git a/priv/repo/migrations/20240131183153_rename_video_filepath_on_media_items.exs b/priv/repo/migrations/20240131183153_rename_video_filepath_on_media_items.exs new file mode 100644 index 0000000..ddfcc53 --- /dev/null +++ b/priv/repo/migrations/20240131183153_rename_video_filepath_on_media_items.exs @@ -0,0 +1,7 @@ +defmodule Pinchflat.Repo.Migrations.RenameVideoFilepathOnMediaItems do + use Ecto.Migration + + def change do + rename table(:media_items), :video_filepath, to: :media_filepath + end +end diff --git a/test/pinchflat/media_client/backends/yt_dlp/metadata_parser_test.exs b/test/pinchflat/media_client/backends/yt_dlp/metadata_parser_test.exs index 313a78b..d414aac 100644 --- a/test/pinchflat/media_client/backends/yt_dlp/metadata_parser_test.exs +++ b/test/pinchflat/media_client/backends/yt_dlp/metadata_parser_test.exs @@ -26,8 +26,8 @@ defmodule Pinchflat.MediaClient.Backends.YtDlp.MediaParserTest do test "it extracts the video filepath", %{metadata: metadata} do result = Parser.parse_for_media_item(metadata) - assert String.contains?(result.video_filepath, "bwRHIkYqYJo") - assert String.ends_with?(result.video_filepath, ".mkv") + assert String.contains?(result.media_filepath, "bwRHIkYqYJo") + assert String.ends_with?(result.media_filepath, ".mkv") end test "it extracts the title", %{metadata: metadata} do diff --git a/test/pinchflat/media_client/video_downloader_test.exs b/test/pinchflat/media_client/video_downloader_test.exs index f172d3e..50d19fe 100644 --- a/test/pinchflat/media_client/video_downloader_test.exs +++ b/test/pinchflat/media_client/video_downloader_test.exs @@ -10,7 +10,7 @@ defmodule Pinchflat.MediaClient.VideoDownloaderTest do setup do media_item = Repo.preload( - media_item_fixture(%{title: nil, video_filepath: nil}), + media_item_fixture(%{title: nil, media_filepath: nil}), [:metadata, channel: :media_profile] ) @@ -33,9 +33,9 @@ defmodule Pinchflat.MediaClient.VideoDownloaderTest do {:ok, render_metadata(:media_metadata)} end) - assert %{video_filepath: nil, title: nil, subtitle_filepaths: []} = media_item + assert %{media_filepath: nil, title: nil, subtitle_filepaths: []} = media_item assert {:ok, updated_media_item} = VideoDownloader.download_for_media_item(media_item) - assert updated_media_item.video_filepath + assert updated_media_item.media_filepath assert updated_media_item.title assert length(updated_media_item.subtitle_filepaths) > 0 end diff --git a/test/pinchflat/media_test.exs b/test/pinchflat/media_test.exs index d7a99cf..d63c77d 100644 --- a/test/pinchflat/media_test.exs +++ b/test/pinchflat/media_test.exs @@ -8,7 +8,7 @@ defmodule Pinchflat.MediaTest do alias Pinchflat.Media alias Pinchflat.Media.MediaItem - @invalid_attrs %{title: nil, media_id: nil, video_filepath: nil} + @invalid_attrs %{title: nil, media_id: nil, media_filepath: nil} describe "schema" do test "media_metadata is deleted when media_item is deleted" do @@ -32,18 +32,18 @@ defmodule Pinchflat.MediaTest do describe "list_pending_media_items_for/1" do test "it returns pending media_items for a given channel" do channel = channel_fixture() - media_item = media_item_fixture(%{channel_id: channel.id, video_filepath: nil}) + media_item = media_item_fixture(%{channel_id: channel.id, media_filepath: nil}) assert Media.list_pending_media_items_for(channel) == [media_item] end - test "it does not return media_items with video_filepath" do + test "it does not return media_items with media_filepath" do channel = channel_fixture() _media_item = media_item_fixture(%{ channel_id: channel.id, - video_filepath: "/video/#{Faker.File.file_name(:video)}" + media_filepath: "/video/#{Faker.File.file_name(:video)}" }) assert Media.list_pending_media_items_for(channel) == [] @@ -62,14 +62,14 @@ defmodule Pinchflat.MediaTest do valid_attrs = %{ media_id: Faker.String.base64(12), title: Faker.Commerce.product_name(), - video_filepath: "/video/#{Faker.File.file_name(:video)}", + media_filepath: "/video/#{Faker.File.file_name(:video)}", channel_id: channel_fixture().id } assert {:ok, %MediaItem{} = media_item} = Media.create_media_item(valid_attrs) assert media_item.title == valid_attrs.title assert media_item.media_id == valid_attrs.media_id - assert media_item.video_filepath == valid_attrs.video_filepath + assert media_item.media_filepath == valid_attrs.media_filepath end test "creating with invalid data returns error changeset" do @@ -84,14 +84,14 @@ defmodule Pinchflat.MediaTest do update_attrs = %{ media_id: Faker.String.base64(12), title: Faker.Commerce.product_name(), - video_filepath: "/video/#{Faker.File.file_name(:video)}", + media_filepath: "/video/#{Faker.File.file_name(:video)}", channel_id: channel_fixture().id } assert {:ok, %MediaItem{} = media_item} = Media.update_media_item(media_item, update_attrs) assert media_item.title == update_attrs.title assert media_item.media_id == update_attrs.media_id - assert media_item.video_filepath == update_attrs.video_filepath + assert media_item.media_filepath == update_attrs.media_filepath end test "updating with invalid data returns error changeset" do diff --git a/test/pinchflat/workers/media_indexing_worker_test.exs b/test/pinchflat/workers/media_indexing_worker_test.exs index 154f9ab..dd044c5 100644 --- a/test/pinchflat/workers/media_indexing_worker_test.exs +++ b/test/pinchflat/workers/media_indexing_worker_test.exs @@ -50,7 +50,7 @@ defmodule Pinchflat.Workers.MediaIndexingWorkerTest do expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, "video1"} end) channel = channel_fixture(index_frequency_minutes: 10) - media_item_fixture(%{channel_id: channel.id, video_filepath: nil}) + media_item_fixture(%{channel_id: channel.id, media_filepath: nil}) perform_job(MediaIndexingWorker, %{id: channel.id}) assert [_, _] = all_enqueued(worker: VideoDownloadWorker) diff --git a/test/pinchflat/workers/video_download_worker_test.exs b/test/pinchflat/workers/video_download_worker_test.exs index d4f0995..da4cb66 100644 --- a/test/pinchflat/workers/video_download_worker_test.exs +++ b/test/pinchflat/workers/video_download_worker_test.exs @@ -11,7 +11,7 @@ defmodule Pinchflat.Workers.VideoDownloadWorkerTest do setup do media_item = Repo.preload( - media_item_fixture(%{video_filepath: nil}), + media_item_fixture(%{media_filepath: nil}), [:metadata, channel: :media_profile] ) @@ -24,9 +24,9 @@ defmodule Pinchflat.Workers.VideoDownloadWorkerTest do {:ok, render_metadata(:media_metadata)} end) - assert media_item.video_filepath == nil + assert media_item.media_filepath == nil perform_job(VideoDownloadWorker, %{id: media_item.id}) - assert Repo.reload(media_item).video_filepath != nil + assert Repo.reload(media_item).media_filepath != nil end test "it saves the metadata to the media_item", %{media_item: media_item} do diff --git a/test/support/fixtures/media_fixtures.ex b/test/support/fixtures/media_fixtures.ex index 7fe9e73..6d0d727 100644 --- a/test/support/fixtures/media_fixtures.ex +++ b/test/support/fixtures/media_fixtures.ex @@ -15,7 +15,7 @@ defmodule Pinchflat.MediaFixtures do |> Enum.into(%{ media_id: Faker.String.base64(12), title: Faker.Commerce.product_name(), - video_filepath: "/video/#{Faker.File.file_name(:video)}", + media_filepath: "/video/#{Faker.File.file_name(:video)}", channel_id: MediaSourceFixtures.channel_fixture().id }) |> Pinchflat.Media.create_media_item()