Added duration checks to pending query
This commit is contained in:
parent
f457235b75
commit
3bfbb55d38
3 changed files with 83 additions and 1 deletions
|
|
@ -75,6 +75,14 @@ defmodule Pinchflat.Media.MediaQuery do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def meets_min_and_max_duration do
|
||||||
|
dynamic(
|
||||||
|
[mi, source],
|
||||||
|
(is_nil(source.min_duration_seconds) or fragment("duration_seconds >= ?", source.min_duration_seconds)) and
|
||||||
|
(is_nil(source.max_duration_seconds) or fragment("duration_seconds <= ?", source.max_duration_seconds))
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def past_retention_period do
|
def past_retention_period do
|
||||||
dynamic(
|
dynamic(
|
||||||
[mi, source],
|
[mi, source],
|
||||||
|
|
@ -123,7 +131,8 @@ defmodule Pinchflat.Media.MediaQuery do
|
||||||
not (^download_prevented()) and
|
not (^download_prevented()) and
|
||||||
^upload_date_after_source_cutoff() and
|
^upload_date_after_source_cutoff() and
|
||||||
^format_matching_profile_preference() and
|
^format_matching_profile_preference() and
|
||||||
^matches_source_title_regex()
|
^matches_source_title_regex() and
|
||||||
|
^meets_min_and_max_duration()
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,8 @@ defmodule PinchflatWeb.Sources.SourceController do
|
||||||
template_id -> Repo.get(Source, template_id) || %Source{}
|
template_id -> Repo.get(Source, template_id) || %Source{}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
IO.inspect(cs_struct)
|
||||||
|
|
||||||
render(conn, :new,
|
render(conn, :new,
|
||||||
media_profiles: media_profiles(),
|
media_profiles: media_profiles(),
|
||||||
layout: get_onboarding_layout(),
|
layout: get_onboarding_layout(),
|
||||||
|
|
@ -62,6 +64,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
||||||
| id: nil,
|
| id: nil,
|
||||||
uuid: nil,
|
uuid: nil,
|
||||||
custom_name: nil,
|
custom_name: nil,
|
||||||
|
description: nil,
|
||||||
collection_name: nil,
|
collection_name: nil,
|
||||||
collection_id: nil,
|
collection_id: nil,
|
||||||
collection_type: nil,
|
collection_type: nil,
|
||||||
|
|
|
||||||
|
|
@ -355,6 +355,48 @@ defmodule Pinchflat.MediaTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "list_pending_media_items_for/1 when min and max durations" do
|
||||||
|
test "returns media items that meet the min and max duration" do
|
||||||
|
source = source_fixture(%{min_duration_seconds: 10, max_duration_seconds: 20})
|
||||||
|
|
||||||
|
_short_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 5})
|
||||||
|
normal_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 15})
|
||||||
|
_long_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 25})
|
||||||
|
|
||||||
|
assert Media.list_pending_media_items_for(source) == [normal_media_item]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not apply a min duration if none is specified" do
|
||||||
|
source = source_fixture(%{min_duration_seconds: nil, max_duration_seconds: 20})
|
||||||
|
|
||||||
|
short_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 5})
|
||||||
|
normal_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 15})
|
||||||
|
_long_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 25})
|
||||||
|
|
||||||
|
assert Media.list_pending_media_items_for(source) == [short_media_item, normal_media_item]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not apply a max duration if none is specified" do
|
||||||
|
source = source_fixture(%{min_duration_seconds: 10, max_duration_seconds: nil})
|
||||||
|
|
||||||
|
_short_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 5})
|
||||||
|
normal_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 15})
|
||||||
|
long_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 25})
|
||||||
|
|
||||||
|
assert Media.list_pending_media_items_for(source) == [normal_media_item, long_media_item]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not apply a min or max duration if none are specified" do
|
||||||
|
source = source_fixture(%{min_duration_seconds: nil, max_duration_seconds: nil})
|
||||||
|
|
||||||
|
short_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 5})
|
||||||
|
normal_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 15})
|
||||||
|
long_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 25})
|
||||||
|
|
||||||
|
assert Media.list_pending_media_items_for(source) == [short_media_item, normal_media_item, long_media_item]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "list_pending_media_items_for/1 when testing download prevention" do
|
describe "list_pending_media_items_for/1 when testing download prevention" do
|
||||||
test "returns only media items that are not prevented from downloading" do
|
test "returns only media items that are not prevented from downloading" do
|
||||||
source = source_fixture()
|
source = source_fixture()
|
||||||
|
|
@ -434,6 +476,34 @@ defmodule Pinchflat.MediaTest do
|
||||||
assert Media.pending_download?(media_item)
|
assert Media.pending_download?(media_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns true if the duration is between the min and max" do
|
||||||
|
source = source_fixture(%{min_duration_seconds: 10, max_duration_seconds: 20})
|
||||||
|
media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 15})
|
||||||
|
|
||||||
|
assert Media.pending_download?(media_item)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns false if the duration is below the min" do
|
||||||
|
source = source_fixture(%{min_duration_seconds: 10, max_duration_seconds: 20})
|
||||||
|
media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 5})
|
||||||
|
|
||||||
|
refute Media.pending_download?(media_item)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns false if the duration is above the max" do
|
||||||
|
source = source_fixture(%{min_duration_seconds: 10, max_duration_seconds: 20})
|
||||||
|
media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 25})
|
||||||
|
|
||||||
|
refute Media.pending_download?(media_item)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns true if there is no min or max duration" do
|
||||||
|
source = source_fixture(%{min_duration_seconds: nil, max_duration_seconds: nil})
|
||||||
|
media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, duration_seconds: 15})
|
||||||
|
|
||||||
|
assert Media.pending_download?(media_item)
|
||||||
|
end
|
||||||
|
|
||||||
test "returns true if the media item is not prevented from downloading" do
|
test "returns true if the media item is not prevented from downloading" do
|
||||||
media_item = media_item_fixture(%{media_filepath: nil, prevent_download: false})
|
media_item = media_item_fixture(%{media_filepath: nil, prevent_download: false})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue