From 0acb5d9edb28183d42c233d942b38cd67f0c7589 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sun, 28 Apr 2024 02:38:00 +0200 Subject: [PATCH] Refactor unrestricting --- internal/config/types.go | 2 +- pkg/http/client.go | 6 +++--- pkg/realdebrid/api.go | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/config/types.go b/internal/config/types.go index ddfbcd3..6013f1e 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -196,7 +196,7 @@ func (z *ZurgConfig) GetDownloadTimeoutSecs() int { func (z *ZurgConfig) GetRateLimitSleepSecs() int { if z.RateLimitSleepSecs == 0 { - return 6 + return 4 } return z.RateLimitSleepSecs } diff --git a/pkg/http/client.go b/pkg/http/client.go index d094f6b..0848527 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -259,7 +259,7 @@ func (r *HTTPClient) shouldRetry(resp *http.Response, reqHasRangeHeader bool, er switch apiErr.Code { case -1: // Internal error return 1 - case 5: // Slow down (retry infinitely) + case 5: // Slow down (retry infinitely), default: 4 secs time.Sleep(time.Duration(rateLimitSleep) * time.Second) return 0 case 6: // Ressource unreachable @@ -272,7 +272,7 @@ func (r *HTTPClient) shouldRetry(resp *http.Response, reqHasRangeHeader bool, er return 1 case 25: // Service unavailable return 1 - case 34: // Too many requests (retry infinitely) + case 34: // Too many requests (retry infinitely), default: 4 secs time.Sleep(time.Duration(rateLimitSleep) * time.Second) return 0 case 36: // Fair Usage Limit @@ -287,7 +287,7 @@ func (r *HTTPClient) shouldRetry(resp *http.Response, reqHasRangeHeader bool, er } if resp != nil { if resp.StatusCode == 429 { - // Too many requests: retry infinitely + // Too many requests: retry infinitely, default: 4 secs time.Sleep(time.Duration(rateLimitSleep) * time.Second) return 0 } diff --git a/pkg/realdebrid/api.go b/pkg/realdebrid/api.go index 3182bca..5cc73c4 100644 --- a/pkg/realdebrid/api.go +++ b/pkg/realdebrid/api.go @@ -69,6 +69,10 @@ func (rd *RealDebrid) UnrestrictCheck(link string) (*Download, error) { func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Download, error) { data := url.Values{} + if strings.HasPrefix(link, "https://real-debrid.com/d/") { + // set link to max 39 chars + link = link[0:39] + } data.Set("link", link) requestBody := strings.NewReader(data.Encode()) @@ -106,6 +110,7 @@ func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Downloa return nil, fmt.Errorf("undecodable response: %v", err) } + // will only check for first byte if serving from rclone if checkFirstByte && !rd.downloadClient.CanFetchFirstByte(response.Download) { return nil, fmt.Errorf("can't fetch first byte") }