From 4c5ae5dc4d363d641ceb5a203df7ab384d81b811 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Thu, 15 Feb 2024 14:00:27 -0800 Subject: [PATCH] added preferred resolution to profiles --- lib/pinchflat/profiles/media_profile.ex | 7 +++++-- .../controllers/media_profiles/media_profile_html.ex | 10 ++++++++++ .../media_profile_html/index.html.heex | 3 +++ .../media_profile_html/media_profile_form.html.heex | 12 ++++++++++++ ...05_add_preferred_resolution_to_media_profiles.exs | 9 +++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20240215215205_add_preferred_resolution_to_media_profiles.exs diff --git a/lib/pinchflat/profiles/media_profile.ex b/lib/pinchflat/profiles/media_profile.ex index e92d1fb..b765055 100644 --- a/lib/pinchflat/profiles/media_profile.ex +++ b/lib/pinchflat/profiles/media_profile.ex @@ -21,6 +21,7 @@ defmodule Pinchflat.Profiles.MediaProfile do embed_metadata shorts_behaviour livestream_behaviour + preferred_resolution )a @required_fields ~w(name output_path_template)a @@ -48,8 +49,10 @@ defmodule Pinchflat.Profiles.MediaProfile do # livestreams _only_ and ignore regular videos. The redundant case # is when one is set to :only and the other is set to :exclude. # See `build_format_clauses` in the Media context for more. - field :shorts_behaviour, Ecto.Enum, values: [:include, :exclude, :only], default: :include - field :livestream_behaviour, Ecto.Enum, values: [:include, :exclude, :only], default: :include + field :shorts_behaviour, Ecto.Enum, values: ~w(include exclude only)a, default: :include + field :livestream_behaviour, Ecto.Enum, values: ~w(include exclude only)a, default: :include + + field :preferred_resolution, Ecto.Enum, values: ~w(2160p 1080p 720p 480p 360p)a, default: :"1080p" has_many :sources, Source diff --git a/lib/pinchflat_web/controllers/media_profiles/media_profile_html.ex b/lib/pinchflat_web/controllers/media_profiles/media_profile_html.ex index 564a4cc..31133c1 100644 --- a/lib/pinchflat_web/controllers/media_profiles/media_profile_html.ex +++ b/lib/pinchflat_web/controllers/media_profiles/media_profile_html.ex @@ -18,4 +18,14 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do {"Only", :only} ] end + + def friendly_resolution_options do + [ + {"2160p", "4k"}, + {"1080p", "1080p"}, + {"720p", "720p"}, + {"480p", "480p"}, + {"360p", "360p"} + ] + end end diff --git a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/index.html.heex b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/index.html.heex index a009702..e1d90dd 100644 --- a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/index.html.heex +++ b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/index.html.heex @@ -19,6 +19,9 @@ <:col :let={media_profile} label="Output Template"> <%= media_profile.output_path_template %> + <:col :let={media_profile} label="Preferred Resolution"> + <%= media_profile.preferred_resolution %> + <:col :let={media_profile} label="" class="flex place-content-evenly"> <.link navigate={~p"/media_profiles/#{media_profile.id}"} diff --git a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/media_profile_form.html.heex b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/media_profile_form.html.heex index 1c653fc..cf82606 100644 --- a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/media_profile_form.html.heex +++ b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/media_profile_form.html.heex @@ -66,6 +66,18 @@ label="Include Livestreams?" /> +

+ Quality Options +

+ + <.input + field={f[:preferred_resolution]} + options={friendly_resolution_options()} + type="select" + label="Preferred Resolution" + help="Will grab the closest available resolution if your preferred is not available" + /> + <:actions> <.button class="mt-15 mb-5 sm:mb-7.5">Save Media profile diff --git a/priv/repo/migrations/20240215215205_add_preferred_resolution_to_media_profiles.exs b/priv/repo/migrations/20240215215205_add_preferred_resolution_to_media_profiles.exs new file mode 100644 index 0000000..3afd7dd --- /dev/null +++ b/priv/repo/migrations/20240215215205_add_preferred_resolution_to_media_profiles.exs @@ -0,0 +1,9 @@ +defmodule Pinchflat.Repo.Migrations.AddPreferredResolutionToMediaProfiles do + use Ecto.Migration + + def change do + alter table(:media_profiles) do + add :preferred_resolution, :string, null: false, default: "1080p" + end + end +end