mirror of
https://github.com/kieraneglin/pinchflat.git
synced 2026-01-23 02:24:24 +00:00
Added limit_rate option to command runner
This commit is contained in:
parent
e993c8e8bf
commit
cc889d6542
2 changed files with 26 additions and 2 deletions
|
|
@ -35,7 +35,7 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
|||
|
||||
output_filepath = generate_output_filepath(addl_opts)
|
||||
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
||||
user_configured_opts = cookie_file_options(addl_opts) ++ sleep_interval_opts(addl_opts)
|
||||
user_configured_opts = cookie_file_options(addl_opts) ++ rate_limit_opts(addl_opts)
|
||||
# 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()
|
||||
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
||||
|
|
@ -116,6 +116,14 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
|||
end
|
||||
end
|
||||
|
||||
defp rate_limit_opts(addl_opts) do
|
||||
throughput_limit = Settings.get!(:download_throughput_limit)
|
||||
sleep_interval_opts = sleep_interval_opts(addl_opts)
|
||||
throughput_option = if throughput_limit, do: [limit_rate: throughput_limit], else: []
|
||||
|
||||
throughput_option ++ sleep_interval_opts
|
||||
end
|
||||
|
||||
defp sleep_interval_opts(addl_opts) do
|
||||
sleep_interval = Settings.get!(:extractor_sleep_interval_seconds)
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "run/4 when testing sleep interval options" do
|
||||
describe "run/4 when testing rate limit options" do
|
||||
test "includes sleep interval options by default" do
|
||||
Settings.set(extractor_sleep_interval_seconds: 5)
|
||||
|
||||
|
|
@ -124,6 +124,22 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
|||
refute String.contains?(output, "--sleep-requests")
|
||||
refute String.contains?(output, "--sleep-subtitles")
|
||||
end
|
||||
|
||||
test "includes limit_rate option when specified" do
|
||||
Settings.set(download_throughput_limit: "100K")
|
||||
|
||||
assert {:ok, output} = Runner.run(@media_url, :foo, [], "")
|
||||
|
||||
assert String.contains?(output, "--limit-rate 100K")
|
||||
end
|
||||
|
||||
test "doesn't include limit_rate option when download_throughput_limit is nil" do
|
||||
Settings.set(download_throughput_limit: nil)
|
||||
|
||||
assert {:ok, output} = Runner.run(@media_url, :foo, [], "")
|
||||
|
||||
refute String.contains?(output, "--limit-rate")
|
||||
end
|
||||
end
|
||||
|
||||
describe "run/4 when testing global options" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue