Added language and format selection to quality option builder

This commit is contained in:
Kieran Eglin 2024-11-26 14:49:25 -08:00
parent edae3174b0
commit 0579694203
No known key found for this signature in database
GPG key ID: 193984967FCF432D

View file

@ -2,10 +2,15 @@ defmodule Pinchflat.Downloading.QualityOptionBuilder do
alias Pinchflat.Settings
alias Pinchflat.Profiles.MediaProfile
# TODO: test
def build(%MediaProfile{preferred_resolution: :audio, media_container: container}) do
acodec = Settings.get!(:audio_codec_preference)
[:extract_audio, format_sort: "+acodec:#{acodec}", audio_format: container || "best"]
[
:extract_audio,
format_sort: "+acodec:#{acodec}",
audio_format: container || "best"
] ++ build_format_string(nil)
end
def build(%MediaProfile{preferred_resolution: resolution_atom, media_container: container}) do
@ -17,6 +22,24 @@ defmodule Pinchflat.Downloading.QualityOptionBuilder do
# Since Plex doesn't support reading metadata from MKV
remux_video: container || "mp4",
format_sort: "res:#{resolution_string},+codec:#{vcodec}:#{acodec}"
]
] ++ build_format_string(nil)
end
# TODO: pass in the entire media profile once we have the language preference column
# TODO: test
defp build_format_string(language_preference) do
if language_preference do
"bestvideo*+bestaudio[#{build_format_modifier(language_preference)}]/bestvideo*+bestaudio/best"
else
"bestvideo*+bestaudio/best"
end
end
# TODO: test
defp build_format_modifier("original"), do: "format_note*=original"
defp build_format_modifier("default"), do: "format_note*=(default)"
# This uses the carat to anchor the language to the beginning of the string
# since that's what's needed to match `en` to `en-US` and `en-GB`, etc. The user
# can always specify the full language code if they want.
defp build_format_modifier(language_code), do: "language^=#{language_code}"
end