Support audio only downloads (#46)
* Adds option to only download audio * Improves helper text for profile options
This commit is contained in:
parent
8cc36928f1
commit
fc52f16475
6 changed files with 83 additions and 22 deletions
|
|
@ -53,7 +53,7 @@ defmodule Pinchflat.Profiles.MediaProfile do
|
|||
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"
|
||||
field :preferred_resolution, Ecto.Enum, values: ~w(2160p 1080p 720p 480p 360p audio)a, default: :"1080p"
|
||||
|
||||
has_many :sources, Source
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilder do
|
|||
{{:download_auto_subs, true}, %{download_subs: true}} ->
|
||||
acc ++ [:write_auto_subs]
|
||||
|
||||
{{:embed_subs, true}, _} ->
|
||||
{{:embed_subs, true}, %{preferred_resolution: pr}} when pr != :audio ->
|
||||
acc ++ [:embed_subs]
|
||||
|
||||
{{:sub_langs, sub_langs}, %{download_subs: true}} ->
|
||||
|
|
@ -63,10 +63,15 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilder do
|
|||
mapped_struct = Map.from_struct(media_profile)
|
||||
|
||||
Enum.reduce(mapped_struct, [], fn attr, acc ->
|
||||
case attr do
|
||||
{:download_thumbnail, true} -> acc ++ [:write_thumbnail]
|
||||
{:embed_thumbnail, true} -> acc ++ [:embed_thumbnail]
|
||||
_ -> acc
|
||||
case {attr, media_profile} do
|
||||
{{:download_thumbnail, true}, _} ->
|
||||
acc ++ [:write_thumbnail]
|
||||
|
||||
{{:embed_thumbnail, true}, %{preferred_resolution: pr}} when pr != :audio ->
|
||||
acc ++ [:embed_thumbnail]
|
||||
|
||||
_ ->
|
||||
acc
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
@ -75,10 +80,15 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilder do
|
|||
mapped_struct = Map.from_struct(media_profile)
|
||||
|
||||
Enum.reduce(mapped_struct, [], fn attr, acc ->
|
||||
case attr do
|
||||
{:download_metadata, true} -> acc ++ [:write_info_json, :clean_info_json]
|
||||
{:embed_metadata, true} -> acc ++ [:embed_metadata]
|
||||
_ -> acc
|
||||
case {attr, media_profile} do
|
||||
{{:download_metadata, true}, _} ->
|
||||
acc ++ [:write_info_json, :clean_info_json]
|
||||
|
||||
{{:embed_metadata, true}, %{preferred_resolution: pr}} when pr != :audio ->
|
||||
acc ++ [:embed_metadata]
|
||||
|
||||
_ ->
|
||||
acc
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
@ -87,6 +97,8 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilder do
|
|||
codec_options = "+codec:avc:m4a"
|
||||
|
||||
case media_profile.preferred_resolution do
|
||||
# Also be aware that :audio disabled all embedding options for thumbnails, subtitles, and metadata
|
||||
:audio -> [format_sort: "ext", format: "bestaudio"]
|
||||
:"360p" -> [format_sort: "res:360,#{codec_options}"]
|
||||
:"480p" -> [format_sort: "res:480,#{codec_options}"]
|
||||
:"720p" -> [format_sort: "res:720,#{codec_options}"]
|
||||
|
|
|
|||
|
|
@ -432,7 +432,7 @@ defmodule PinchflatWeb.CoreComponents do
|
|||
|
||||
def label(assigns) do
|
||||
~H"""
|
||||
<label for={@for} class="mt-5 mb-2 block text-md font-medium text-black dark:text-white">
|
||||
<label for={@for} class="mt-5 mb-2 inline-block text-md font-medium text-black dark:text-white">
|
||||
<%= render_slot(@inner_block) %>
|
||||
</label>
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -21,11 +21,12 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do
|
|||
|
||||
def friendly_resolution_options do
|
||||
[
|
||||
{"2160p", "4k"},
|
||||
{"4k", "2160p"},
|
||||
{"1080p", "1080p"},
|
||||
{"720p", "720p"},
|
||||
{"480p", "480p"},
|
||||
{"360p", "360p"}
|
||||
{"360p", "360p"},
|
||||
{"Audio Only", "audio"}
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,15 @@
|
|||
help="Must end with .{{ ext }}. See below for more details. I promise the default is good for most cases (required)"
|
||||
/>
|
||||
|
||||
<h3 class="mb-4 mt-8 text-2xl text-black dark:text-white">
|
||||
<h3 class="mt-8 text-2xl text-black dark:text-white">
|
||||
Subtitle Options
|
||||
</h3>
|
||||
<.input field={f[:download_subs]} type="toggle" label="Download Subtitles" />
|
||||
<.input
|
||||
field={f[:download_subs]}
|
||||
type="toggle"
|
||||
label="Download Subtitles"
|
||||
help="Downloads subtitle files alongside media file"
|
||||
/>
|
||||
<.input
|
||||
field={f[:download_auto_subs]}
|
||||
type="toggle"
|
||||
|
|
@ -45,10 +50,15 @@
|
|||
help="Use commas for multiple languages (eg: en,de)"
|
||||
/>
|
||||
|
||||
<h3 class="mb-4 mt-8 text-2xl text-black dark:text-white">
|
||||
<h3 class="mt-8 text-2xl text-black dark:text-white">
|
||||
Thumbnail Options
|
||||
</h3>
|
||||
<.input field={f[:download_thumbnail]} type="toggle" label="Download Thumbnail" />
|
||||
<.input
|
||||
field={f[:download_thumbnail]}
|
||||
type="toggle"
|
||||
label="Download Thumbnail"
|
||||
help="Downloads thumbnail alongside media file"
|
||||
/>
|
||||
<.input
|
||||
field={f[:embed_thumbnail]}
|
||||
type="toggle"
|
||||
|
|
@ -56,10 +66,15 @@
|
|||
help="Embeds thumbnail in the video file itself, if supported (recommended)"
|
||||
/>
|
||||
|
||||
<h3 class="mb-4 mt-8 text-2xl text-black dark:text-white">
|
||||
<h3 class="mt-8 text-2xl text-black dark:text-white">
|
||||
Metadata Options
|
||||
</h3>
|
||||
<.input field={f[:download_metadata]} type="toggle" label="Download Metadata" />
|
||||
<.input
|
||||
field={f[:download_metadata]}
|
||||
type="toggle"
|
||||
label="Download Metadata"
|
||||
help="Downloads metadata file alongside media file"
|
||||
/>
|
||||
<.input
|
||||
field={f[:embed_metadata]}
|
||||
type="toggle"
|
||||
|
|
@ -67,7 +82,7 @@
|
|||
help="Embeds metadata in the video file itself, if supported (recommended)"
|
||||
/>
|
||||
|
||||
<h3 class="mb-4 mt-8 text-2xl text-black dark:text-white">
|
||||
<h3 class="mt-8 text-2xl text-black dark:text-white">
|
||||
Release Format Options
|
||||
</h3>
|
||||
|
||||
|
|
@ -85,7 +100,7 @@
|
|||
label="Include Livestreams?"
|
||||
/>
|
||||
|
||||
<h3 class="mb-4 mt-8 text-2xl text-black dark:text-white">
|
||||
<h3 class="mt-8 text-2xl text-black dark:text-white">
|
||||
Quality Options
|
||||
</h3>
|
||||
|
||||
|
|
@ -94,7 +109,7 @@
|
|||
options={friendly_resolution_options()}
|
||||
type="select"
|
||||
label="Preferred Resolution"
|
||||
help="Will grab the closest available resolution if your preferred is not available"
|
||||
help="Will grab the closest available resolution if your preferred is not available. Setting to 'Audio Only' negates embedding options."
|
||||
/>
|
||||
|
||||
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto">Save Media profile</.button>
|
||||
|
|
|
|||
|
|
@ -82,6 +82,14 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilderTest do
|
|||
assert :embed_subs in res
|
||||
end
|
||||
|
||||
test "doesn't include :embed_subs option when preferred_resolution is :audio", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{embed_subs: true, preferred_resolution: :audio})
|
||||
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
refute :embed_subs in res
|
||||
end
|
||||
|
||||
test "includes sub_langs option when download_subs is true", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{download_subs: true, sub_langs: "en"})
|
||||
|
||||
|
|
@ -125,6 +133,14 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilderTest do
|
|||
assert :embed_thumbnail in res
|
||||
end
|
||||
|
||||
test "doesn't include :embed_thumbnail option when preferred_resolution is :audio", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{embed_thumbnail: true, preferred_resolution: :audio})
|
||||
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
refute :embed_thumbnail in res
|
||||
end
|
||||
|
||||
test "doesn't include these options when not specified", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{embed_thumbnail: false, download_thumbnail: false})
|
||||
|
||||
|
|
@ -153,6 +169,14 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilderTest do
|
|||
assert :embed_metadata in res
|
||||
end
|
||||
|
||||
test "doesn't include :embed_metadata option when preferred_resolution is :audio", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{embed_metadata: true, preferred_resolution: :audio})
|
||||
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
refute :embed_metadata in res
|
||||
end
|
||||
|
||||
test "doesn't include these options when not specified", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{embed_metadata: false, download_metadata: false})
|
||||
|
||||
|
|
@ -172,6 +196,15 @@ defmodule Pinchflat.Profiles.Options.YtDlp.DownloadOptionBuilderTest do
|
|||
|
||||
assert {:format_sort, "res:1080,+codec:avc:m4a"} in res
|
||||
end
|
||||
|
||||
test "it includes quality options for audio only", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{preferred_resolution: :audio})
|
||||
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
assert {:format, "bestaudio"} in res
|
||||
assert {:format_sort, "ext"} in res
|
||||
end
|
||||
end
|
||||
|
||||
defp update_media_profile_attribute(media_item_with_preloads, attrs) do
|
||||
|
|
|
|||
Loading…
Reference in a new issue