[BACKEND] Enable throttle protection by default
This commit is contained in:
parent
9871f62b91
commit
0a2d6e274f
6 changed files with 57 additions and 5 deletions
|
|
@ -185,6 +185,13 @@ class ThrottleProtectionOptions(ToggleableOptionsDictValidator):
|
||||||
class ThrottleProtectionPlugin(Plugin[ThrottleProtectionOptions]):
|
class ThrottleProtectionPlugin(Plugin[ThrottleProtectionOptions]):
|
||||||
plugin_options_type = ThrottleProtectionOptions
|
plugin_options_type = ThrottleProtectionOptions
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def perform_sleep(cls, sleep_time: float) -> None:
|
||||||
|
"""
|
||||||
|
Wrapper to be able to mock
|
||||||
|
"""
|
||||||
|
time.sleep(sleep_time)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
options: ThrottleProtectionOptions,
|
options: ThrottleProtectionOptions,
|
||||||
|
|
@ -239,7 +246,7 @@ class ThrottleProtectionPlugin(Plugin[ThrottleProtectionOptions]):
|
||||||
self._subscription_max_downloads is not None
|
self._subscription_max_downloads is not None
|
||||||
and self._subscription_download_counter == 0
|
and self._subscription_download_counter == 0
|
||||||
):
|
):
|
||||||
logger.debug(
|
logger.info(
|
||||||
"Setting subscription max downloads to %d", self._subscription_max_downloads
|
"Setting subscription max downloads to %d", self._subscription_max_downloads
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -248,8 +255,8 @@ class ThrottleProtectionPlugin(Plugin[ThrottleProtectionOptions]):
|
||||||
|
|
||||||
if self.plugin_options.sleep_per_download_s:
|
if self.plugin_options.sleep_per_download_s:
|
||||||
sleep_time = self.plugin_options.sleep_per_download_s.randomized_float()
|
sleep_time = self.plugin_options.sleep_per_download_s.randomized_float()
|
||||||
logger.debug("Sleeping between downloads for %0.2f seconds", sleep_time)
|
logger.info("Sleeping between downloads for %0.2f seconds", sleep_time)
|
||||||
time.sleep(sleep_time)
|
self.perform_sleep(sleep_time)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -265,5 +272,5 @@ class ThrottleProtectionPlugin(Plugin[ThrottleProtectionOptions]):
|
||||||
|
|
||||||
if self.plugin_options.sleep_per_subscription_s:
|
if self.plugin_options.sleep_per_subscription_s:
|
||||||
sleep_time = self.plugin_options.sleep_per_subscription_s.randomized_float()
|
sleep_time = self.plugin_options.sleep_per_subscription_s.randomized_float()
|
||||||
logger.debug("Sleeping between subscriptions for %0.2f seconds", sleep_time)
|
logger.info("Sleeping between subscriptions for %0.2f seconds", sleep_time)
|
||||||
time.sleep(sleep_time)
|
self.perform_sleep(sleep_time)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
presets:
|
||||||
|
|
||||||
|
_throttle_protection:
|
||||||
|
throttle_protection:
|
||||||
|
enable: >-
|
||||||
|
{
|
||||||
|
%print(
|
||||||
|
%if(
|
||||||
|
enable_throttle_protection,
|
||||||
|
"Throttle protection is enabled. Disable using the override variable `enable_throttle_protection: False`",
|
||||||
|
"Throttle protection is disabled. Use at your own risk!"
|
||||||
|
),
|
||||||
|
enable_throttle_protection
|
||||||
|
)
|
||||||
|
}
|
||||||
|
sleep_per_request_s:
|
||||||
|
min: 3.5
|
||||||
|
max: 3.5
|
||||||
|
sleep_per_download_s:
|
||||||
|
min: 13.8
|
||||||
|
max: 28.4
|
||||||
|
sleep_per_subscription_s:
|
||||||
|
min: 16.3
|
||||||
|
max: 26.1
|
||||||
|
overrides:
|
||||||
|
enable_throttle_protection: True
|
||||||
|
|
@ -2,6 +2,11 @@ presets:
|
||||||
|
|
||||||
|
|
||||||
_music_base:
|
_music_base:
|
||||||
|
preset:
|
||||||
|
# ytdl-sub includes throttle prootection by default or all prebuilt presets.
|
||||||
|
# Can be disabled with override variable `enable_throttle_protection: False`
|
||||||
|
- "_throttle_protection"
|
||||||
|
|
||||||
output_options:
|
output_options:
|
||||||
output_directory: "{music_directory}"
|
output_directory: "{music_directory}"
|
||||||
file_name: "{track_full_path}"
|
file_name: "{track_full_path}"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ presets:
|
||||||
_music_video_base:
|
_music_video_base:
|
||||||
|
|
||||||
preset:
|
preset:
|
||||||
|
# ytdl-sub includes throttle prootection by default or all prebuilt presets.
|
||||||
|
# Can be disabled with override variable `enable_throttle_protection: False`
|
||||||
|
- "_throttle_protection"
|
||||||
- "_url_categorized"
|
- "_url_categorized"
|
||||||
|
|
||||||
output_options:
|
output_options:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@ presets:
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
||||||
_episode_base:
|
_episode_base:
|
||||||
|
preset:
|
||||||
|
# ytdl-sub includes throttle prootection by default or all prebuilt presets.
|
||||||
|
# Can be disabled with override variable `enable_throttle_protection: False`
|
||||||
|
- "_throttle_protection"
|
||||||
|
|
||||||
output_options:
|
output_options:
|
||||||
output_directory: "{tv_show_directory}/{tv_show_name_sanitized}"
|
output_directory: "{tv_show_directory}/{tv_show_name_sanitized}"
|
||||||
file_name: "{episode_file_path}.{ext}"
|
file_name: "{episode_file_path}.{ext}"
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ from ytdl_sub.downloaders.url.downloader import MultiUrlDownloader
|
||||||
from ytdl_sub.downloaders.ytdlp import YTDLP
|
from ytdl_sub.downloaders.ytdlp import YTDLP
|
||||||
from ytdl_sub.entries.script.variable_definitions import VARIABLES
|
from ytdl_sub.entries.script.variable_definitions import VARIABLES
|
||||||
from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
|
from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
|
||||||
|
from ytdl_sub.plugins.throttle_protection import ThrottleProtectionPlugin
|
||||||
|
|
||||||
v: VariableDefinitions = VARIABLES
|
v: VariableDefinitions = VARIABLES
|
||||||
|
|
||||||
|
|
@ -264,6 +265,11 @@ def mock_download_collection_entries(
|
||||||
patch.object(
|
patch.object(
|
||||||
MultiUrlDownloader, "_extract_entry_info_with_retry", new=lambda _, entry: entry
|
MultiUrlDownloader, "_extract_entry_info_with_retry", new=lambda _, entry: entry
|
||||||
),
|
),
|
||||||
|
# Throttle protection is included in all prebuilt presets. Mock the sleep avoid
|
||||||
|
# actual sleeps
|
||||||
|
patch.object(
|
||||||
|
ThrottleProtectionPlugin, "perform_sleep", new=lambda _1, _2: None
|
||||||
|
)
|
||||||
):
|
):
|
||||||
# Stub out metadata. TODO: update this if we do metadata plugins
|
# Stub out metadata. TODO: update this if we do metadata plugins
|
||||||
yield
|
yield
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue