Always verify links

This commit is contained in:
Ben Adrian Sarmiento
2024-07-09 22:21:32 +02:00
parent e71e7e4d92
commit b56ad95835
2 changed files with 16 additions and 17 deletions

View File

@@ -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)

View File

@@ -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,7 +99,6 @@ 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")
@@ -114,7 +110,6 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
}
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)