Rename variables for easy reference
This commit is contained in:
@@ -201,6 +201,7 @@ func (r *HTTPClient) ensureReachableHost(req *http.Request) {
|
||||
if !strings.Contains(req.Host, ".download.real-debrid.") {
|
||||
return
|
||||
}
|
||||
// skip CDN servers
|
||||
if req.Host[0] >= 'a' && req.Host[0] <= 'z' {
|
||||
return
|
||||
}
|
||||
@@ -216,16 +217,18 @@ func (r *HTTPClient) ensureReachableHost(req *http.Request) {
|
||||
} else if strings.HasSuffix(req.Host, ".cloud") {
|
||||
newHost = strings.Replace(req.Host, ".cloud", ".com", 1)
|
||||
}
|
||||
// check if newHost is reachable
|
||||
if r.CheckIfHostIsReachable(newHost) {
|
||||
req.Host = newHost
|
||||
req.URL.Host = req.Host
|
||||
return
|
||||
}
|
||||
|
||||
// just pick a random host
|
||||
req.Host = r.hosts[rand.Intn(len(r.hosts))]
|
||||
req.URL.Host = req.Host
|
||||
}
|
||||
|
||||
// CheckIfHostIsReachable checks if the given host is passed in the list of reachable hosts
|
||||
func (r *HTTPClient) CheckIfHostIsReachable(reqHost string) bool {
|
||||
for _, host := range r.hosts {
|
||||
if reqHost == host {
|
||||
|
||||
@@ -84,9 +84,11 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
|
||||
if expiry, ok := rd.verifiedLinks.Get(download.ID); ok && expiry > time.Now().Unix() {
|
||||
return download, nil
|
||||
} else if ok {
|
||||
// if the link is expired, remove it from the verified links cache
|
||||
rd.verifiedLinks.Remove(download.ID)
|
||||
}
|
||||
|
||||
// check if the link is still valid (not in the cache or expired)
|
||||
err := rd.downloadClient.VerifyLink(download.Download)
|
||||
if utils.IsBytesLimitReached(err) {
|
||||
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
|
||||
@@ -95,6 +97,7 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
|
||||
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
|
||||
return download, nil
|
||||
}
|
||||
// if verification failed, remove the link from the token map
|
||||
tokenMap.Remove(link)
|
||||
}
|
||||
|
||||
@@ -419,8 +422,10 @@ func (rd *RealDebrid) DownloadFile(req *http.Request) (*http.Response, error) {
|
||||
// MonitorExpiredTokens is a permanent job for monitoring expired tokens if they are still expired
|
||||
func (rd *RealDebrid) MonitorExpiredTokens() {
|
||||
sleepPeriod := 1 * time.Minute
|
||||
i := 0
|
||||
rd.workerPool.Submit(func() {
|
||||
for {
|
||||
i++
|
||||
expiredTokens := rd.TokenManager.GetExpiredTokens()
|
||||
for _, token := range expiredTokens {
|
||||
tokenMap, _ := rd.UnrestrictMap.Get(token)
|
||||
@@ -432,7 +437,12 @@ func (rd *RealDebrid) MonitorExpiredTokens() {
|
||||
}
|
||||
err := rd.downloadClient.VerifyLink(download.Download)
|
||||
if err != nil {
|
||||
skipAll = utils.IsBytesLimitReached(err)
|
||||
if utils.IsBytesLimitReached(err) {
|
||||
if i%15 == 0 {
|
||||
rd.log.Debugf("Token %s is still expired", utils.MaskToken(token))
|
||||
}
|
||||
skipAll = true
|
||||
}
|
||||
return
|
||||
}
|
||||
stillExpired = false
|
||||
|
||||
Reference in New Issue
Block a user