Additional configs

This commit is contained in:
Ben Sarmiento
2023-11-28 11:39:08 +01:00
parent 00c7e04795
commit a42a5eeb80
5 changed files with 30 additions and 7 deletions

View File

@@ -39,7 +39,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
apiClient := zurghttp.NewHTTPClient(config.GetToken(), 5, 15, config, log.Named("httpclient")) apiClient := zurghttp.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), config.GetRealDebridTimeout(), config, log.Named("httpclient"))
rd := realdebrid.NewRealDebrid(apiClient, log.Named("realdebrid")) rd := realdebrid.NewRealDebrid(apiClient, log.Named("realdebrid"))
@@ -52,7 +52,7 @@ func main() {
torrentMgr := torrent.NewTorrentManager(config, rd, p, log.Named("manager")) torrentMgr := torrent.NewTorrentManager(config, rd, p, log.Named("manager"))
downloadClient := zurghttp.NewHTTPClient("", 5, 0, config, log.Named("dlclient")) downloadClient := zurghttp.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), 0, config, log.Named("dlclient"))
getfile := universal.NewGetFile(downloadClient) getfile := universal.NewGetFile(downloadClient)
mux := http.NewServeMux() mux := http.NewServeMux()

View File

@@ -1,8 +1,7 @@
# Zurg configuration version # Zurg configuration version
zurg: v1 zurg: v1
token: YOUR_RD_API_TOKEN # https://real-debrid.com/apitoken token: YOUR_RD_API_TOKEN # https://real-debrid.com/apitoken
# basic functionality
host: "[::]" # do not change this if you are running it inside a docker container host: "[::]" # do not change this if you are running it inside a docker container
port: 9999 # do not change this if you are running it inside a docker container port: 9999 # do not change this if you are running it inside a docker container
concurrent_workers: 200 concurrent_workers: 200
@@ -11,7 +10,9 @@ check_for_changes_every_secs: 15
unrestrict_workers: 10 # since unrestricting has a different rate limit, use a different worker pool. decrease this if you are getting 429s 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 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 rate_limit_sleep_secs: 6 # wait time after getting a 429 from Real-Debrid API
realdebrid_timeout_secs: 60 # api timeout
retries_until_failed: 5 # api failures until considered failed
# misc configs
enable_repair: true # BEWARE! THERE CAN ONLY BE 1 INSTANCE OF ZURG THAT SHOULD REPAIR YOUR TORRENTS 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 retain_folder_name_extension: false # if true, zurg won't modify the filenames from real-debrid
retain_rd_torrent_name: false # if true, it will strictly follow RD API returned torrent name which should make this more compatible with rdt-client retain_rd_torrent_name: false # if true, it will strictly follow RD API returned torrent name which should make this more compatible with rdt-client
@@ -20,7 +21,7 @@ on_library_update: |
do do
echo "detected update on: $arg" echo "detected update on: $arg"
done done
# network configs
network_buffer_size: 1048576 # 1 MiB network_buffer_size: 1048576 # 1 MiB
serve_from_rclone: false serve_from_rclone: false
force_ipv6: true force_ipv6: true

View File

@@ -23,6 +23,8 @@ type ConfigInterface interface {
GetUnrestrictWorkers() int GetUnrestrictWorkers() int
GetReleaseUnrestrictAfterMs() int GetReleaseUnrestrictAfterMs() int
GetRateLimitSleepSeconds() int GetRateLimitSleepSeconds() int
GetRealDebridTimeout() int
GetRetriesUntilFailed() int
} }
type ZurgConfig struct { type ZurgConfig struct {
@@ -44,6 +46,8 @@ type ZurgConfig struct {
PreferredHosts []string `yaml:"preferred_hosts"` PreferredHosts []string `yaml:"preferred_hosts"`
ServeFromRclone bool `yaml:"serve_from_rclone"` ServeFromRclone bool `yaml:"serve_from_rclone"`
ForceIPv6 bool `yaml:"force_ipv6"` ForceIPv6 bool `yaml:"force_ipv6"`
RealDebridTimeout int `yaml:"realdebrid_timeout_secs"`
RetriesUntilFailed int `yaml:"retries_until_failed"`
} }
func (z *ZurgConfig) GetToken() string { func (z *ZurgConfig) GetToken() string {
@@ -144,3 +148,17 @@ func (z *ZurgConfig) GetRateLimitSleepSeconds() int {
} }
return z.RateLimitSleepSeconds return z.RateLimitSleepSeconds
} }
func (z *ZurgConfig) GetRealDebridTimeout() int {
if z.RealDebridTimeout == 0 {
return 60
}
return z.RealDebridTimeout
}
func (z *ZurgConfig) GetRetriesUntilFailed() int {
if z.RetriesUntilFailed == 0 {
return 5
}
return z.RetriesUntilFailed
}

View File

@@ -82,6 +82,7 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i
if download, exists := t.DownloadCache.Get(link); exists { if download, exists := t.DownloadCache.Get(link); exists {
if c.ShouldServeFromRclone() && t.Api.CanFetchFirstByte(download.Download) { if c.ShouldServeFromRclone() && t.Api.CanFetchFirstByte(download.Download) {
redirect(w, r, download.Download, c) redirect(w, r, download.Download, c)
return
} else { } else {
err := gf.streamCachedLinkToResponse(download.Download, w, r, t, c, log) err := gf.streamCachedLinkToResponse(download.Download, w, r, t, c, log)
if err == nil { if err == nil {

View File

@@ -88,6 +88,9 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
} }
time.Sleep(r.Backoff(attempt)) time.Sleep(r.Backoff(attempt))
} }
if resp != nil {
resp.Body.Close()
}
} }
} }
} }
@@ -109,7 +112,7 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, cfg config.Con
}, },
ShouldRetry: func(resp *http.Response, err error) int { ShouldRetry: func(resp *http.Response, err error) int {
if resp != nil { if resp != nil {
if resp.StatusCode == 429 || resp.StatusCode == 400 { if resp.StatusCode == 429 || resp.StatusCode == 400 || resp.StatusCode == 403 {
return 0 // retry but don't increment attempt return 0 // retry but don't increment attempt
} }
return -1 // don't retry return -1 // don't retry