renamed video_filepath to media_filepath

This commit is contained in:
Kieran Eglin 2024-01-31 10:35:05 -08:00
parent 73171e069e
commit 969ce0d00f
No known key found for this signature in database
GPG key ID: 193984967FCF432D
10 changed files with 30 additions and 23 deletions

View file

@ -19,14 +19,14 @@ defmodule Pinchflat.Media do
@doc """ @doc """
Returns a list of pending media_items for a given channel, where 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{}, ...]. Returns [%MediaItem{}, ...].
""" """
def list_pending_media_items_for(%Channel{} = channel) do def list_pending_media_items_for(%Channel{} = channel) do
from( from(
m in MediaItem, 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() |> Repo.all()
end end

View file

@ -11,12 +11,12 @@ defmodule Pinchflat.Media.MediaItem do
alias Pinchflat.Media.MediaMetadata alias Pinchflat.Media.MediaMetadata
@required_fields ~w(media_id channel_id)a @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 schema "media_items" do
field :title, :string field :title, :string
field :media_id, :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 # 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. # 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. # Will very likely revisit because I can't leave well-enough alone.

View file

@ -30,7 +30,7 @@ defmodule Pinchflat.MediaClient.Backends.YtDlp.MetadataParser do
defp parse_media_metadata(metadata) do defp parse_media_metadata(metadata) do
%{ %{
title: metadata["title"], title: metadata["title"],
video_filepath: metadata["filepath"] media_filepath: metadata["filepath"]
} }
end end

View file

@ -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

View file

@ -26,8 +26,8 @@ defmodule Pinchflat.MediaClient.Backends.YtDlp.MediaParserTest do
test "it extracts the video filepath", %{metadata: metadata} do test "it extracts the video filepath", %{metadata: metadata} do
result = Parser.parse_for_media_item(metadata) result = Parser.parse_for_media_item(metadata)
assert String.contains?(result.video_filepath, "bwRHIkYqYJo") assert String.contains?(result.media_filepath, "bwRHIkYqYJo")
assert String.ends_with?(result.video_filepath, ".mkv") assert String.ends_with?(result.media_filepath, ".mkv")
end end
test "it extracts the title", %{metadata: metadata} do test "it extracts the title", %{metadata: metadata} do

View file

@ -10,7 +10,7 @@ defmodule Pinchflat.MediaClient.VideoDownloaderTest do
setup do setup do
media_item = media_item =
Repo.preload( Repo.preload(
media_item_fixture(%{title: nil, video_filepath: nil}), media_item_fixture(%{title: nil, media_filepath: nil}),
[:metadata, channel: :media_profile] [:metadata, channel: :media_profile]
) )
@ -33,9 +33,9 @@ defmodule Pinchflat.MediaClient.VideoDownloaderTest do
{:ok, render_metadata(:media_metadata)} {:ok, render_metadata(:media_metadata)}
end) 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 {: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 updated_media_item.title
assert length(updated_media_item.subtitle_filepaths) > 0 assert length(updated_media_item.subtitle_filepaths) > 0
end end

View file

@ -8,7 +8,7 @@ defmodule Pinchflat.MediaTest do
alias Pinchflat.Media alias Pinchflat.Media
alias Pinchflat.Media.MediaItem 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 describe "schema" do
test "media_metadata is deleted when media_item is deleted" 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 describe "list_pending_media_items_for/1" do
test "it returns pending media_items for a given channel" do test "it returns pending media_items for a given channel" do
channel = channel_fixture() 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] assert Media.list_pending_media_items_for(channel) == [media_item]
end 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() channel = channel_fixture()
_media_item = _media_item =
media_item_fixture(%{ media_item_fixture(%{
channel_id: channel.id, 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) == [] assert Media.list_pending_media_items_for(channel) == []
@ -62,14 +62,14 @@ defmodule Pinchflat.MediaTest do
valid_attrs = %{ valid_attrs = %{
media_id: Faker.String.base64(12), media_id: Faker.String.base64(12),
title: Faker.Commerce.product_name(), 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 channel_id: channel_fixture().id
} }
assert {:ok, %MediaItem{} = media_item} = Media.create_media_item(valid_attrs) assert {:ok, %MediaItem{} = media_item} = Media.create_media_item(valid_attrs)
assert media_item.title == valid_attrs.title assert media_item.title == valid_attrs.title
assert media_item.media_id == valid_attrs.media_id 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 end
test "creating with invalid data returns error changeset" do test "creating with invalid data returns error changeset" do
@ -84,14 +84,14 @@ defmodule Pinchflat.MediaTest do
update_attrs = %{ update_attrs = %{
media_id: Faker.String.base64(12), media_id: Faker.String.base64(12),
title: Faker.Commerce.product_name(), 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 channel_id: channel_fixture().id
} }
assert {:ok, %MediaItem{} = media_item} = Media.update_media_item(media_item, update_attrs) assert {:ok, %MediaItem{} = media_item} = Media.update_media_item(media_item, update_attrs)
assert media_item.title == update_attrs.title assert media_item.title == update_attrs.title
assert media_item.media_id == update_attrs.media_id 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 end
test "updating with invalid data returns error changeset" do test "updating with invalid data returns error changeset" do

View file

@ -50,7 +50,7 @@ defmodule Pinchflat.Workers.MediaIndexingWorkerTest do
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, "video1"} end) expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, "video1"} end)
channel = channel_fixture(index_frequency_minutes: 10) 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}) perform_job(MediaIndexingWorker, %{id: channel.id})
assert [_, _] = all_enqueued(worker: VideoDownloadWorker) assert [_, _] = all_enqueued(worker: VideoDownloadWorker)

View file

@ -11,7 +11,7 @@ defmodule Pinchflat.Workers.VideoDownloadWorkerTest do
setup do setup do
media_item = media_item =
Repo.preload( Repo.preload(
media_item_fixture(%{video_filepath: nil}), media_item_fixture(%{media_filepath: nil}),
[:metadata, channel: :media_profile] [:metadata, channel: :media_profile]
) )
@ -24,9 +24,9 @@ defmodule Pinchflat.Workers.VideoDownloadWorkerTest do
{:ok, render_metadata(:media_metadata)} {:ok, render_metadata(:media_metadata)}
end) end)
assert media_item.video_filepath == nil assert media_item.media_filepath == nil
perform_job(VideoDownloadWorker, %{id: media_item.id}) perform_job(VideoDownloadWorker, %{id: media_item.id})
assert Repo.reload(media_item).video_filepath != nil assert Repo.reload(media_item).media_filepath != nil
end end
test "it saves the metadata to the media_item", %{media_item: media_item} do test "it saves the metadata to the media_item", %{media_item: media_item} do

View file

@ -15,7 +15,7 @@ defmodule Pinchflat.MediaFixtures do
|> Enum.into(%{ |> Enum.into(%{
media_id: Faker.String.base64(12), media_id: Faker.String.base64(12),
title: Faker.Commerce.product_name(), 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 channel_id: MediaSourceFixtures.channel_fixture().id
}) })
|> Pinchflat.Media.create_media_item() |> Pinchflat.Media.create_media_item()