Add resolution option (#21)
* added preferred resolution to profiles * Add resolution to download option builder
This commit is contained in:
@@ -21,6 +21,7 @@ defmodule Pinchflat.Profiles.MediaProfile do
|
|||||||
embed_metadata
|
embed_metadata
|
||||||
shorts_behaviour
|
shorts_behaviour
|
||||||
livestream_behaviour
|
livestream_behaviour
|
||||||
|
preferred_resolution
|
||||||
)a
|
)a
|
||||||
|
|
||||||
@required_fields ~w(name output_path_template)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
|
# livestreams _only_ and ignore regular videos. The redundant case
|
||||||
# is when one is set to :only and the other is set to :exclude.
|
# is when one is set to :only and the other is set to :exclude.
|
||||||
# See `build_format_clauses` in the Media context for more.
|
# See `build_format_clauses` in the Media context for more.
|
||||||
field :shorts_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: [:include, :exclude, :only], 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
|
has_many :sources, Source
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilder do
|
|||||||
subtitle_options(media_profile) ++
|
subtitle_options(media_profile) ++
|
||||||
thumbnail_options(media_profile) ++
|
thumbnail_options(media_profile) ++
|
||||||
metadata_options(media_profile) ++
|
metadata_options(media_profile) ++
|
||||||
|
quality_options(media_profile) ++
|
||||||
output_options(media_profile)
|
output_options(media_profile)
|
||||||
|
|
||||||
{:ok, built_options}
|
{:ok, built_options}
|
||||||
@@ -87,6 +88,19 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilder do
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp quality_options(media_profile) do
|
||||||
|
codec_options = "+codec:avc:m4a"
|
||||||
|
|
||||||
|
case media_profile.preferred_resolution do
|
||||||
|
:"360p" -> [format_sort: "res:360,#{codec_options}"]
|
||||||
|
:"480p" -> [format_sort: "res:480,#{codec_options}"]
|
||||||
|
:"720p" -> [format_sort: "res:720,#{codec_options}"]
|
||||||
|
:"1080p" -> [format_sort: "res:1080,#{codec_options}"]
|
||||||
|
:"1440p" -> [format_sort: "res:1440,#{codec_options}"]
|
||||||
|
:"2160p" -> [format_sort: "res:2160,#{codec_options}"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp output_options(media_profile) do
|
defp output_options(media_profile) do
|
||||||
{:ok, output_path} = OutputPathBuilder.build(media_profile.output_path_template)
|
{:ok, output_path} = OutputPathBuilder.build(media_profile.output_path_template)
|
||||||
|
|
||||||
|
|||||||
@@ -18,4 +18,14 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do
|
|||||||
{"Only", :only}
|
{"Only", :only}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def friendly_resolution_options do
|
||||||
|
[
|
||||||
|
{"2160p", "4k"},
|
||||||
|
{"1080p", "1080p"},
|
||||||
|
{"720p", "720p"},
|
||||||
|
{"480p", "480p"},
|
||||||
|
{"360p", "360p"}
|
||||||
|
]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
<:col :let={media_profile} label="Output Template">
|
<:col :let={media_profile} label="Output Template">
|
||||||
<code class="text-sm"><%= media_profile.output_path_template %></code>
|
<code class="text-sm"><%= media_profile.output_path_template %></code>
|
||||||
</:col>
|
</:col>
|
||||||
|
<:col :let={media_profile} label="Preferred Resolution">
|
||||||
|
<%= media_profile.preferred_resolution %>
|
||||||
|
</:col>
|
||||||
<:col :let={media_profile} label="" class="flex place-content-evenly">
|
<:col :let={media_profile} label="" class="flex place-content-evenly">
|
||||||
<.link
|
<.link
|
||||||
navigate={~p"/media_profiles/#{media_profile.id}"}
|
navigate={~p"/media_profiles/#{media_profile.id}"}
|
||||||
|
|||||||
+12
@@ -66,6 +66,18 @@
|
|||||||
label="Include Livestreams?"
|
label="Include Livestreams?"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<h3 class="mb-4 mt-8 text-2xl text-black dark:text-white">
|
||||||
|
Quality Options
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<.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>
|
<:actions>
|
||||||
<.button class="mt-15 mb-5 sm:mb-7.5">Save Media profile</.button>
|
<.button class="mt-15 mb-5 sm:mb-7.5">Save Media profile</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -158,4 +158,12 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilderTest do
|
|||||||
refute :embed_metadata in res
|
refute :embed_metadata in res
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "build/1 when testing quality options" do
|
||||||
|
test "it includes quality options" do
|
||||||
|
assert {:ok, res} = DownloadOptionBuilder.build(@media_profile)
|
||||||
|
|
||||||
|
assert {:format_sort, "res:1080,+codec:avc:m4a"} in res
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user