diff --git a/lib/pinchflat/media/media_item.ex b/lib/pinchflat/media/media_item.ex index 7a4fb32..8eeb97e 100644 --- a/lib/pinchflat/media/media_item.ex +++ b/lib/pinchflat/media/media_item.ex @@ -112,6 +112,9 @@ defmodule Pinchflat.Media.MediaItem do |> dynamic_default(:uuid, fn _ -> Ecto.UUID.generate() end) |> update_upload_date_index() |> validate_required(@required_fields) + # Validate that the title does NOT start with "youtube video #" since that indicates a restriction by YouTube. + # See issue #549 for more information. + |> validate_format(:title, ~r/^(?!youtube video #)/) |> unique_constraint([:media_id, :source_id]) end diff --git a/test/pinchflat/media_test.exs b/test/pinchflat/media_test.exs index 891502c..6becd5b 100644 --- a/test/pinchflat/media_test.exs +++ b/test/pinchflat/media_test.exs @@ -921,6 +921,14 @@ defmodule Pinchflat.MediaTest do media_item = media_item_fixture() assert %Ecto.Changeset{} = Media.change_media_item(media_item) end + + test "validates the title doesn't start with 'youtube video #'" do + # This is to account for youtube restricting indexing. See issue #549 for more + media_item = media_item_fixture() + + assert %Ecto.Changeset{valid?: false} = Media.change_media_item(media_item, %{title: "youtube video #123"}) + assert %Ecto.Changeset{valid?: true} = Media.change_media_item(media_item, %{title: "any other title"}) + end end describe "change_media_item/1 when testing upload_date_index and source is a channel" do diff --git a/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs b/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs index e410b3c..c9598a1 100644 --- a/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs +++ b/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs @@ -290,6 +290,29 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do assert %Ecto.Changeset{} = changeset end + test "doesn't blow up if the media item cannot be saved", %{source: source} do + stub(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, _addl_opts -> + response = + Phoenix.json_library().encode!(%{ + id: "video1", + # This is a disallowed title - set MediaItem changeset or issue #549 + title: "youtube video #123", + original_url: "https://example.com/video1", + live_status: "not_live", + description: "desc1", + aspect_ratio: 1.67, + duration: 12.34, + upload_date: "20210101" + }) + + {:ok, response} + end) + + assert [changeset] = SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source) + + assert %Ecto.Changeset{} = changeset + end + test "passes the source's download options to the yt-dlp runner", %{source: source} do expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, opts, _ot, _addl_opts -> assert {:output, "/tmp/test/media/%(title)S.%(ext)S"} in opts