From 05796942034d5bb8810208ba9015d5d2bf4ff8f9 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Tue, 26 Nov 2024 14:49:25 -0800 Subject: [PATCH] Added language and format selection to quality option builder --- .../downloading/quality_option_builder.ex | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/pinchflat/downloading/quality_option_builder.ex b/lib/pinchflat/downloading/quality_option_builder.ex index da4a057..210b528 100644 --- a/lib/pinchflat/downloading/quality_option_builder.ex +++ b/lib/pinchflat/downloading/quality_option_builder.ex @@ -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