Prevented saving/updating of media items if being throttled by youtube
This commit is contained in:
parent
eb51fc655a
commit
ced26f3dd1
3 changed files with 34 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue