Fix for invalid_download_code

This commit is contained in:
Ben Adrian Sarmiento
2024-06-30 23:29:29 +02:00
parent bf193a2656
commit f3d6230935
5 changed files with 46 additions and 20 deletions

View File

@@ -276,11 +276,14 @@ func (r *HTTPClient) shouldRetry(req *http.Request, resp *http.Response, err err
return -1 // don't retry
}
} else if downloadErr, ok := err.(*DownloadErrorResponse); ok {
switch downloadErr.Code {
case http.StatusServiceUnavailable: // Service unavailable
switch downloadErr.Message {
case "bytes_limit_reached": // 503
return -1
default:
case "invalid_download_code": // 404
time.Sleep(time.Duration(rateLimitSleep) * time.Second)
return 1
default:
return 1 // retry
}
}
if err != nil && strings.Contains(err.Error(), "timeout") {

View File

@@ -78,12 +78,12 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
continue
}
if err != nil {
return nil, err
if err == nil {
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+60*60*24)
return download, nil
}
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+60*60*24)
return download, nil
rd.verifiedLinks.Remove(download.ID)
tokenMap.Remove(link)
}
download, err := rd.UnrestrictLinkWithToken(link, token)