diff --git a/config.example.yml b/config.example.yml index b3dc261..b7b504c 100644 --- a/config.example.yml +++ b/config.example.yml @@ -7,8 +7,10 @@ host: "[::]" # do not change this if you are running it inside a docker containe port: 9999 # do not change this if you are running it inside a docker container concurrent_workers: 200 check_for_changes_every_secs: 15 +# reliability configs unrestrict_workers: 10 # since unrestricting has a different rate limit, use a different worker pool. decrease this if you are getting 429s release_unrestrict_after_ms: 100 # wait time for every unrestrict worker to be released. increase this if you are getting 429s +rate_limit_sleep_secs: 6 # wait time after getting a 429 from Real-Debrid API enable_repair: true # BEWARE! THERE CAN ONLY BE 1 INSTANCE OF ZURG THAT SHOULD REPAIR YOUR TORRENTS retain_folder_name_extension: false # if true, zurg won't modify the filenames from real-debrid diff --git a/internal/config/types.go b/internal/config/types.go index 5d31034..be9888f 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -22,6 +22,7 @@ type ConfigInterface interface { ShouldForceIPv6() bool GetUnrestrictWorkers() int GetReleaseUnrestrictAfterMs() int + GetRateLimitSleepSeconds() int } type ZurgConfig struct { @@ -32,6 +33,7 @@ type ZurgConfig struct { NumOfWorkers int `yaml:"concurrent_workers"` UnrestrictWorkers int `yaml:"unrestrict_workers"` ReleaseUnrestrictAfterMs int `yaml:"release_unrestrict_after_ms"` + RateLimitSleepSeconds int `yaml:"rate_limit_sleep_secs"` RefreshEverySeconds int `yaml:"check_for_changes_every_secs"` CanRepair bool `yaml:"enable_repair"` OnLibraryUpdate string `yaml:"on_library_update"` @@ -135,3 +137,10 @@ func (z *ZurgConfig) GetReleaseUnrestrictAfterMs() int { } return z.ReleaseUnrestrictAfterMs } + +func (z *ZurgConfig) GetRateLimitSleepSeconds() int { + if z.RateLimitSleepSeconds == 0 { + return 4 + } + return z.RateLimitSleepSeconds +} diff --git a/pkg/http/client.go b/pkg/http/client.go index f254136..b4ad99b 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -80,7 +80,7 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) { return resp, err } else { if val == 0 { - time.Sleep(8 * time.Second) // extra delay + time.Sleep(time.Duration(r.config.GetRateLimitSleepSeconds()) * time.Second) // extra delay } else { attempt += val if attempt > r.MaxRetries {