Refactor unrestricting

This commit is contained in:
Ben Sarmiento
2024-04-28 02:38:00 +02:00
parent eb04ed378b
commit 0acb5d9edb
3 changed files with 9 additions and 4 deletions

View File

@@ -196,7 +196,7 @@ func (z *ZurgConfig) GetDownloadTimeoutSecs() int {
func (z *ZurgConfig) GetRateLimitSleepSecs() int { func (z *ZurgConfig) GetRateLimitSleepSecs() int {
if z.RateLimitSleepSecs == 0 { if z.RateLimitSleepSecs == 0 {
return 6 return 4
} }
return z.RateLimitSleepSecs return z.RateLimitSleepSecs
} }

View File

@@ -259,7 +259,7 @@ func (r *HTTPClient) shouldRetry(resp *http.Response, reqHasRangeHeader bool, er
switch apiErr.Code { switch apiErr.Code {
case -1: // Internal error case -1: // Internal error
return 1 return 1
case 5: // Slow down (retry infinitely) case 5: // Slow down (retry infinitely), default: 4 secs
time.Sleep(time.Duration(rateLimitSleep) * time.Second) time.Sleep(time.Duration(rateLimitSleep) * time.Second)
return 0 return 0
case 6: // Ressource unreachable case 6: // Ressource unreachable
@@ -272,7 +272,7 @@ func (r *HTTPClient) shouldRetry(resp *http.Response, reqHasRangeHeader bool, er
return 1 return 1
case 25: // Service unavailable case 25: // Service unavailable
return 1 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) time.Sleep(time.Duration(rateLimitSleep) * time.Second)
return 0 return 0
case 36: // Fair Usage Limit case 36: // Fair Usage Limit
@@ -287,7 +287,7 @@ func (r *HTTPClient) shouldRetry(resp *http.Response, reqHasRangeHeader bool, er
} }
if resp != nil { if resp != nil {
if resp.StatusCode == 429 { if resp.StatusCode == 429 {
// Too many requests: retry infinitely // Too many requests: retry infinitely, default: 4 secs
time.Sleep(time.Duration(rateLimitSleep) * time.Second) time.Sleep(time.Duration(rateLimitSleep) * time.Second)
return 0 return 0
} }

View File

@@ -69,6 +69,10 @@ func (rd *RealDebrid) UnrestrictCheck(link string) (*Download, error) {
func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Download, error) { func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Download, error) {
data := url.Values{} 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) data.Set("link", link)
requestBody := strings.NewReader(data.Encode()) 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) 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) { if checkFirstByte && !rd.downloadClient.CanFetchFirstByte(response.Download) {
return nil, fmt.Errorf("can't fetch first byte") return nil, fmt.Errorf("can't fetch first byte")
} }