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 {
|
if apiErr, ok := err.(*ApiErrorResponse); ok {
|
||||||
switch apiErr.Code {
|
switch apiErr.Code {
|
||||||
case 5: // Slow down (retry infinitely)
|
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)
|
case 34: // Too many requests (retry infinitely)
|
||||||
secs := r.backoff(attempts, rateLimitSleep)
|
secs := r.backoff(attempts, rateLimitSleep)
|
||||||
r.log.Debugf("API rate limit reached, retrying in %d seconds", secs/time.Second)
|
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
|
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) {
|
func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
|
||||||
for {
|
for {
|
||||||
@@ -70,9 +70,6 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
|
|||||||
tokenMap, _ := rd.UnrestrictMap.Get(token)
|
tokenMap, _ := rd.UnrestrictMap.Get(token)
|
||||||
if tokenMap.Has(link) {
|
if tokenMap.Has(link) {
|
||||||
download, _ := tokenMap.Get(link)
|
download, _ := tokenMap.Get(link)
|
||||||
if !rd.cfg.ShouldServeFromRclone() {
|
|
||||||
return download, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the link is in the verified links cache
|
// check if the link is in the verified links cache
|
||||||
if expiry, ok := rd.verifiedLinks.Get(download.ID); ok && expiry > time.Now().Unix() {
|
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)
|
tokenMap.Set(link, download)
|
||||||
|
|
||||||
if rd.cfg.ShouldServeFromRclone() {
|
err = rd.downloadClient.VerifyLink(download.Download)
|
||||||
err = rd.downloadClient.VerifyLink(download.Download)
|
if utils.IsBytesLimitReached(err) {
|
||||||
if utils.IsBytesLimitReached(err) {
|
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
|
||||||
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
|
continue
|
||||||
continue
|
} else if utils.IsInvalidDownloadCode(err) {
|
||||||
} else if utils.IsInvalidDownloadCode(err) {
|
continue
|
||||||
continue
|
} else if err != nil {
|
||||||
} else if err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
|
||||||
|
|
||||||
return download, err
|
return download, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,7 +432,7 @@ func (rd *RealDebrid) MonitorExpiredTokens() {
|
|||||||
}
|
}
|
||||||
stillExpired = false
|
stillExpired = false
|
||||||
skipAll = true
|
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 {
|
if !stillExpired {
|
||||||
rd.TokenManager.SetTokenAsUnexpired(token)
|
rd.TokenManager.SetTokenAsUnexpired(token)
|
||||||
|
|||||||
Reference in New Issue
Block a user