Implemented title regex filtering

This commit is contained in:
Kieran Eglin 2024-03-20 10:47:02 -07:00
parent af8f8c7b2f
commit 98dd3d5e57
No known key found for this signature in database
GPG key ID: 193984967FCF432D
31 changed files with 54 additions and 10 deletions

View file

@ -25,6 +25,21 @@ config :pinchflat,
basic_auth_username: System.get_env("BASIC_AUTH_USERNAME"),
basic_auth_password: System.get_env("BASIC_AUTH_PASSWORD")
arch_string = to_string(:erlang.system_info(:system_architecture))
system_arch =
cond do
String.contains?(arch_string, "arm") -> "arm"
String.contains?(arch_string, "aarch") -> "arm"
String.contains?(arch_string, "x86") -> "x86"
true -> "unknown"
end
config :pinchflat, Pinchflat.Repo,
load_extensions: [
Path.join([:code.priv_dir(:pinchflat), "repo", "extensions", "sqlean-linux-#{system_arch}", "sqlean"])
]
if config_env() == :prod do
config_path =
System.get_env("CONFIG_PATH") ||

View file

@ -66,6 +66,7 @@ defmodule Pinchflat.Media do
|> where([mi], mi.source_id == ^source.id and is_nil(mi.media_filepath))
|> where(^build_format_clauses(media_profile))
|> where(^maybe_apply_cutoff_date(source))
|> where(^maybe_apply_title_regex(source))
|> Repo.maybe_limit(limit)
|> Repo.all()
end
@ -247,6 +248,14 @@ defmodule Pinchflat.Media do
end
end
defp maybe_apply_title_regex(source) do
if source.title_filter_regex do
dynamic([mi], fragment("regexp_like(?, ?)", mi.title, ^source.title_filter_regex))
else
dynamic(true)
end
end
defp build_format_clauses(media_profile) do
mapped_struct = Map.from_struct(media_profile)

View file

@ -238,7 +238,7 @@
/>
</section>
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto">Save Media profile</.button>
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto" rounding="rounded-lg">Save Media profile</.button>
</section>
<div class="rounded-sm dark:bg-meta-4 p-4 md:p-6 mb-5">

View file

@ -87,17 +87,17 @@
<p class="text-sm mt-2">
Tread carefully
</p>
<.input
field={f[:title_filter_regex]}
type="text"
label="Title Filter Regex"
placeholder="(?i)^How to Bike$"
help="A PCRE-compatible regex. Only media with titles that match this regex will be downloaded. Look up 'SQLean Regex docs' for more"
/>
</section>
<.input
field={f[:title_filter_regex]}
type="text"
label="Title Filter Regex"
placeholder="/^How to Bike/i"
help="A PCRE-compatible regex. Only media with titles that match this regex will be downloaded"
/>
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto">Save Source</.button>
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto" rounding="rounded-lg">Save Source</.button>
<div class="rounded-sm dark:bg-meta-4 p-4 md:p-6 mb-5">
<.fast_indexing_help />

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -239,6 +239,26 @@ defmodule Pinchflat.MediaTest do
end
end
describe "list_pending_media_items_for/1 when testing title regex" do
test "returns only media items that match the title regex" do
source = source_fixture(%{title_filter_regex: "(?i)^FOO$"})
matching_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "foo"})
_non_matching_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "bar"})
assert Media.list_pending_media_items_for(source) == [matching_media_item]
end
test "does not apply a regex if none is specified" do
source = source_fixture(%{title_filter_regex: nil})
media_item_one = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "foo"})
media_item_two = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "bar"})
assert Media.list_pending_media_items_for(source) == [media_item_one, media_item_two]
end
end
describe "list_downloaded_media_items_for/1" do
test "returns only media items with a media_filepath" do
source = source_fixture()