Adds restrict-filenames to command runner
This commit is contained in:
parent
6eb5b97b76
commit
f0d6acb213
2 changed files with 37 additions and 15 deletions
|
|
@ -35,7 +35,7 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||||
|
|
||||||
output_filepath = generate_output_filepath(addl_opts)
|
output_filepath = generate_output_filepath(addl_opts)
|
||||||
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
||||||
user_configured_opts = cookie_file_options(addl_opts) ++ rate_limit_opts(addl_opts)
|
user_configured_opts = cookie_file_options(addl_opts) ++ rate_limit_options(addl_opts) ++ misc_options()
|
||||||
# These must stay in exactly this order, hence why I'm giving it its own variable.
|
# These must stay in exactly this order, hence why I'm giving it its own variable.
|
||||||
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts ++ global_options()
|
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts ++ global_options()
|
||||||
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
||||||
|
|
@ -116,7 +116,22 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp rate_limit_opts(addl_opts) do
|
defp add_cookie_file do
|
||||||
|
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||||
|
filename_options_map = %{cookies: "cookies.txt"}
|
||||||
|
|
||||||
|
Enum.reduce(filename_options_map, [], fn {opt_name, filename}, acc ->
|
||||||
|
filepath = Path.join(base_dir, filename)
|
||||||
|
|
||||||
|
if FSUtils.exists_and_nonempty?(filepath) do
|
||||||
|
[{opt_name, filepath} | acc]
|
||||||
|
else
|
||||||
|
acc
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp rate_limit_options(addl_opts) do
|
||||||
throughput_limit = Settings.get!(:download_throughput_limit)
|
throughput_limit = Settings.get!(:download_throughput_limit)
|
||||||
sleep_interval_opts = sleep_interval_opts(addl_opts)
|
sleep_interval_opts = sleep_interval_opts(addl_opts)
|
||||||
throughput_option = if throughput_limit, do: [limit_rate: throughput_limit], else: []
|
throughput_option = if throughput_limit, do: [limit_rate: throughput_limit], else: []
|
||||||
|
|
@ -138,19 +153,8 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp add_cookie_file do
|
defp misc_options do
|
||||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
if Settings.get!(:restrict_filenames), do: [:restrict_filenames], else: []
|
||||||
filename_options_map = %{cookies: "cookies.txt"}
|
|
||||||
|
|
||||||
Enum.reduce(filename_options_map, [], fn {opt_name, filename}, acc ->
|
|
||||||
filepath = Path.join(base_dir, filename)
|
|
||||||
|
|
||||||
if FSUtils.exists_and_nonempty?(filepath) do
|
|
||||||
[{opt_name, filepath} | acc]
|
|
||||||
else
|
|
||||||
acc
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp backend_executable do
|
defp backend_executable do
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,24 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "run/4 when testing misc options" do
|
||||||
|
test "includes --restrict-filenames when enabled" do
|
||||||
|
Settings.set(restrict_filenames: true)
|
||||||
|
|
||||||
|
assert {:ok, output} = Runner.run(@media_url, :foo, [], "")
|
||||||
|
|
||||||
|
assert String.contains?(output, "--restrict-filenames")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "doesn't include --restrict-filenames when disabled" do
|
||||||
|
Settings.set(restrict_filenames: false)
|
||||||
|
|
||||||
|
assert {:ok, output} = Runner.run(@media_url, :foo, [], "")
|
||||||
|
|
||||||
|
refute String.contains?(output, "--restrict-filenames")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "version/0" do
|
describe "version/0" do
|
||||||
test "adds the version arg" do
|
test "adds the version arg" do
|
||||||
assert {:ok, output} = Runner.version()
|
assert {:ok, output} = Runner.version()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue