From af8f8c7b2ffa588a1d4fa6aaf612870dcb6cdde1 Mon Sep 17 00:00:00 2001
From: Kieran Eglin
Date: Wed, 20 Mar 2024 08:43:54 -0700
Subject: [PATCH] Added regex field and UI to source form
---
lib/pinchflat/sources/source.ex | 13 ++++++++-----
.../sources/source_html/source_form.html.heex | 8 ++++++++
.../20240320153902_add_title_regex_to_source.exs | 9 +++++++++
3 files changed, 25 insertions(+), 5 deletions(-)
create mode 100644 priv/repo/migrations/20240320153902_add_title_regex_to_source.exs
diff --git a/lib/pinchflat/sources/source.ex b/lib/pinchflat/sources/source.ex
index ec3075f..266ac85 100644
--- a/lib/pinchflat/sources/source.ex
+++ b/lib/pinchflat/sources/source.ex
@@ -28,6 +28,7 @@ defmodule Pinchflat.Sources.Source do
last_indexed_at
original_url
download_cutoff_date
+ title_filter_regex
media_profile_id
)a
@@ -57,11 +58,6 @@ defmodule Pinchflat.Sources.Source do
field :collection_name, :string
field :collection_id, :string
field :collection_type, Ecto.Enum, values: [:channel, :playlist]
- field :nfo_filepath, :string
- field :poster_filepath, :string
- field :fanart_filepath, :string
- field :banner_filepath, :string
- field :series_directory, :string
field :index_frequency_minutes, :integer, default: 60 * 24
field :fast_index, :boolean, default: false
field :download_media, :boolean, default: true
@@ -69,6 +65,13 @@ defmodule Pinchflat.Sources.Source do
# Only download media items that were published after this date
field :download_cutoff_date, :date
field :original_url, :string
+ field :title_filter_regex, :string
+
+ field :series_directory, :string
+ field :nfo_filepath, :string
+ field :poster_filepath, :string
+ field :fanart_filepath, :string
+ field :banner_filepath, :string
belongs_to :media_profile, MediaProfile
diff --git a/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex b/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex
index 7e9ec5a..b3ad2a5 100644
--- a/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex
+++ b/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex
@@ -89,6 +89,14 @@
+ <.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
diff --git a/priv/repo/migrations/20240320153902_add_title_regex_to_source.exs b/priv/repo/migrations/20240320153902_add_title_regex_to_source.exs
new file mode 100644
index 0000000..ab45144
--- /dev/null
+++ b/priv/repo/migrations/20240320153902_add_title_regex_to_source.exs
@@ -0,0 +1,9 @@
+defmodule Pinchflat.Repo.Migrations.AddTitleRegexToSource do
+ use Ecto.Migration
+
+ def change do
+ alter table(:sources) do
+ add :title_filter_regex, :string
+ end
+ end
+end