# Policy for the unified simulation enforcer. # This file is used by `bin/ytops-client policy-enforcer --live` to manage # both the authentication and download simulation environments from a single process. simulation_parameters: # --- Common Redis settings for all tools --- # The enforcer will connect to two different Redis environments (key prefixes) # based on these settings, applying the corresponding policies to each. env_file: ".env" auth_env: "sim_auth" download_env: "sim_download" # How often the enforcer should wake up and apply all policies. interval_seconds: 2 # --- Dynamic Profile Group Templates --- # The policy enforcer will find all profile prefixes matching a pattern in Redis # and apply the settings from the matching template. This avoids having to list # every profile group manually. # NOTE: The policy enforcer tool must be updated to support this format. profile_group_templates: - pattern: "user*" auth: max_active_profiles: 1 rotate_after_requests: 5 rest_duration_minutes_on_rotation: 0.20 wait_download_finish_per_group: true max_wait_for_downloads_minutes: 240 download: rotate_after_requests: 0 rest_duration_minutes_on_rotation: 0.2 # --- Policies for the Authentication Simulation --- auth_policy_enforcer_config: # Ban if 2 failures occur within a 1-minute window. #ban_on_failures: 2 #ban_on_failures_window_minutes: 1 # The standard rest policy is disabled, as rotation is handled by the profile group. # New rate limit policy to enforce requests-per-hour limits. # For guest sessions, the limit is ~300 videos/hour. rate_limit_requests: 0 rate_limit_window_minutes: 60 rate_limit_rest_duration_minutes: 5 rest_after_requests: 0 rest_duration_minutes: 10 # NOTE on Rate Limits: With the default yt-dlp settings, the rate limit for guest # sessions is ~300 videos/hour (~1000 webpage/player requests per hour). # For accounts, it is ~2000 videos/hour (~4000 webpage/player requests per hour). # The settings below should be configured to respect these limits. # New setting for load balancing across profile groups. # "longest_idle": Activates the profile that has been idle the longest across all groups (based on last_used time). # This is a global FIFO strategy that effectively cycles through profiles regardless of their group. # "least_loaded": Prioritizes activating a profile from the group with the fewest pending downloads. # If multiple groups have zero pending downloads, it acts as a FIFO queue, activating # the one that finished its last download batch the earliest. This is useful when you want # to ensure a group finishes its entire workload before another group starts. profile_selection_strategy: "longest_idle" # Enforce a total limit of active profiles across all groups defined below. # Set to 1 to ensure only one group's profile is active at any time. global_max_active_profiles: 1 # The 'profile_groups' section is now inherited from 'profile_group_definitions' above. # The enforcer logic should be updated to read from there. proxy_work_minutes: 0 proxy_rest_duration_minutes: 0 # Global maximum time a proxy can be active before being rested, regardless of # other rules. Acts as a safety net. Set to 0 to disable. max_global_proxy_active_minutes: 0 rest_duration_on_max_active: 10 # Proxy-level ban on failure burst is disabled. proxy_ban_on_failures: 0 proxy_ban_window_minutes: 2 # Clean up locks held for more than 16 minutes (960s) to prevent stuck workers. # This should be longer than the docker container timeout (15m). unlock_stale_locks_after_seconds: 960 # A short post-task cooldown for auth simulation profiles. When a batch is finished, # the profile is put into COOLDOWN briefly. This prevents a worker from immediately # re-locking the same profile, giving the policy enforcer a window to perform rotation. unlock_cooldown_seconds: 0 # --- Cross-simulation synchronization --- # This section is simplified because the link between auth and download profiles # is now defined in the `profile_group_definitions`. cross_simulation_sync: # Which states to synchronize from auth to download. sync_states: - "BANNED" # If true, a BANNED state on an auth profile will force the download profile to also be BANNED. enforce_auth_lead: true # CRITICAL: Ensures the correct download profile GROUP is active. sync_active_profile: true # When an auth profile is in the 'waiting_downloads' state, ensure the matching download profile is active. sync_waiting_downloads: true # --- Policies for the Download Simulation --- download_policy_enforcer_config: # Ban if 1 failure occurs within a 1-minute window. ban_on_failures: 1 ban_on_failures_window_minutes: 1 # Standard rest policy is disabled in favor of group rotation. # New rate limit policy to enforce requests-per-hour limits. # For guest sessions, the limit is ~300 videos/hour. We set it slightly lower to be safe. rate_limit_requests: 280 rate_limit_window_minutes: 60 rate_limit_rest_duration_minutes: 5 rest_after_requests: 0 rest_duration_minutes: 20 # NOTE on Rate Limits: With the default yt-dlp settings, the rate limit for guest # sessions is ~300 videos/hour (~1000 webpage/player requests per hour). # For accounts, it is ~2000 videos/hour (~4000 webpage/player requests per hour). # The settings below should be configured to respect these limits. # The 'profile_groups' section is now inherited from 'profile_group_definitions' above. # The enforcer logic should be updated to read from there. # Time-based proxy rules are disabled. proxy_work_minutes: 0 proxy_rest_duration_minutes: 10 # Global maximum time a proxy can be active before being rested, regardless of # other rules. Acts as a safety net. Set to 0 to disable. max_global_proxy_active_minutes: 0 rest_duration_on_max_active: 10 # Proxy-level ban on failure burst is disabled. proxy_ban_on_failures: 3 proxy_ban_window_minutes: 1 # Clean up download locks held for more than 16 minutes (960s) to allow for long downloads. # This should be longer than the docker container timeout (15m). unlock_stale_locks_after_seconds: 960 # After a profile is used for a download, unlock it but put it in COOLDOWN # state for 2-3s. This is enforced by the worker, which reads this config from Redis. unlock_cooldown_seconds: [2, 3]