From fc52f16475ef9962c9f4cee834b0d261053ef206 Mon Sep 17 00:00:00 2001 From: Kieran Date: Sat, 2 Mar 2024 13:01:47 -0800 Subject: [PATCH] Support audio only downloads (#46) * Adds option to only download audio * Improves helper text for profile options --- lib/pinchflat/profiles/media_profile.ex | 2 +- .../options/yt_dlp/download_option_builder.ex | 30 ++++++++++++----- .../components/core_components.ex | 2 +- .../media_profiles/media_profile_html.ex | 5 +-- .../media_profile_form.html.heex | 33 ++++++++++++++----- .../yt_dlp/download_option_builder_test.exs | 33 +++++++++++++++++++ 6 files changed, 83 insertions(+), 22 deletions(-) diff --git a/lib/pinchflat/profiles/media_profile.ex b/lib/pinchflat/profiles/media_profile.ex index db3f888..9398b0e 100644 --- a/lib/pinchflat/profiles/media_profile.ex +++ b/lib/pinchflat/profiles/media_profile.ex @@ -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 diff --git a/lib/pinchflat/profiles/options/yt_dlp/download_option_builder.ex b/lib/pinchflat/profiles/options/yt_dlp/download_option_builder.ex index e9b37cf..ac5c0de 100644 --- a/lib/pinchflat/profiles/options/yt_dlp/download_option_builder.ex +++ b/lib/pinchflat/profiles/options/yt_dlp/download_option_builder.ex @@ -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}"] diff --git a/lib/pinchflat_web/components/core_components.ex b/lib/pinchflat_web/components/core_components.ex index 09d842c..3bd8486 100644 --- a/lib/pinchflat_web/components/core_components.ex +++ b/lib/pinchflat_web/components/core_components.ex @@ -432,7 +432,7 @@ defmodule PinchflatWeb.CoreComponents do def label(assigns) do ~H""" -