Always verify links
This commit is contained in:
@@ -258,6 +258,10 @@ func (r *HTTPClient) shouldRetry(req *http.Request, resp *http.Response, err err
|
||||
if apiErr, ok := err.(*ApiErrorResponse); ok {
|
||||
switch apiErr.Code {
|
||||
case 5: // Slow down (retry infinitely)
|
||||
secs := r.backoff(attempts, rateLimitSleep)
|
||||
r.log.Debugf("API rate limit reached, retrying in %d seconds", secs/time.Second)
|
||||
time.Sleep(secs)
|
||||
return 0
|
||||
case 34: // Too many requests (retry infinitely)
|
||||
secs := r.backoff(attempts, rateLimitSleep)
|
||||
r.log.Debugf("API rate limit reached, retrying in %d seconds", secs/time.Second)
|
||||
|
||||
@@ -56,7 +56,7 @@ func NewRealDebrid(apiClient, unrestrictClient, downloadClient *zurghttp.HTTPCli
|
||||
return rd
|
||||
}
|
||||
|
||||
const DOWNLOAD_LINK_EXPIRY = 60 * 60 * 24
|
||||
const DOWNLOAD_LINK_EXPIRY = 60 * 60 * 1.5 // 1.5 hours
|
||||
|
||||
func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
|
||||
for {
|
||||
@@ -70,9 +70,6 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
|
||||
tokenMap, _ := rd.UnrestrictMap.Get(token)
|
||||
if tokenMap.Has(link) {
|
||||
download, _ := tokenMap.Get(link)
|
||||
if !rd.cfg.ShouldServeFromRclone() {
|
||||
return download, nil
|
||||
}
|
||||
|
||||
// check if the link is in the verified links cache
|
||||
if expiry, ok := rd.verifiedLinks.Get(download.ID); ok && expiry > time.Now().Unix() {
|
||||
@@ -102,20 +99,18 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
|
||||
|
||||
tokenMap.Set(link, download)
|
||||
|
||||
if rd.cfg.ShouldServeFromRclone() {
|
||||
err = rd.downloadClient.VerifyLink(download.Download)
|
||||
if utils.IsBytesLimitReached(err) {
|
||||
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
|
||||
continue
|
||||
} else if utils.IsInvalidDownloadCode(err) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
|
||||
err = rd.downloadClient.VerifyLink(download.Download)
|
||||
if utils.IsBytesLimitReached(err) {
|
||||
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
|
||||
continue
|
||||
} else if utils.IsInvalidDownloadCode(err) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
|
||||
|
||||
return download, err
|
||||
}
|
||||
}
|
||||
@@ -437,7 +432,7 @@ func (rd *RealDebrid) MonitorExpiredTokens() {
|
||||
}
|
||||
stillExpired = false
|
||||
skipAll = true
|
||||
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+60*60*24)
|
||||
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
|
||||
})
|
||||
if !stillExpired {
|
||||
rd.TokenManager.SetTokenAsUnexpired(token)
|
||||
|
||||
Reference in New Issue
Block a user