[Enhancement] Add download rate limiting to app settings (#646)

* Added rate limit column to settings

* Added limit_rate option to command runner

* Added rate limit to settings form
This commit is contained in:
Kieran
2025-03-11 15:45:56 -07:00
committed by GitHub
parent 0fbf810cb6
commit 4554648ba7
6 changed files with 47 additions and 4 deletions
+4 -1
View File
@@ -15,7 +15,8 @@ defmodule Pinchflat.Settings.Setting do
:video_codec_preference,
:audio_codec_preference,
:youtube_api_key,
:extractor_sleep_interval_seconds
:extractor_sleep_interval_seconds,
:download_throughput_limit
]
@required_fields [
@@ -35,6 +36,8 @@ defmodule Pinchflat.Settings.Setting do
field :youtube_api_key, :string
field :route_token, :string
field :extractor_sleep_interval_seconds, :integer, default: 0
# This is a string because it accepts values like "100K" or "4.2M"
field :download_throughput_limit, :string
field :video_codec_preference, :string
field :audio_codec_preference, :string
+9 -1
View File
@@ -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)
@@ -47,7 +47,14 @@
placeholder="0"
type="number"
label="Sleep Interval (seconds)"
help="Sleep interval in seconds between each extractor request. Must be a positive whole number (or set to 0 to disable)"
help="Sleep interval in seconds between each extractor request. Must be a positive whole number. Set to 0 to disable"
/>
<.input
field={f[:download_throughput_limit]}
placeholder="4.2M"
label="Download Throughput"
help="Sets the max throughput when downloading media. Examples: '50K' or '4.2M'. Leave blank to disable"
/>
</section>
</section>