Remove GetRandomPreferredHost usage

This commit is contained in:
Ben Sarmiento
2024-01-26 17:58:31 +01:00
parent 29a11ec286
commit 8d4cdbbd1f
3 changed files with 6 additions and 18 deletions

View File

@@ -1,6 +1,8 @@
package config package config
import "math/rand" import (
"math/rand"
)
type ConfigInterface interface { type ConfigInterface interface {
GetConfig() ZurgConfig GetConfig() ZurgConfig

View File

@@ -78,15 +78,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
t.log.Fatalf("Cannot get downloads: %v", err) t.log.Fatalf("Cannot get downloads: %v", err)
} }
for i := range downloads { for i := range downloads {
if !t.DownloadCache.Has(downloads[i].Link) { t.cacheDownload(&downloads[i])
if strings.Contains(downloads[i].Download, "download.real-debrid.") {
prefHost := t.Config.GetRandomPreferredHost()
if prefHost != "" {
downloads[i].Download = replaceHostInURL(downloads[i].Download, prefHost)
}
}
t.cacheDownload(&downloads[i])
}
} }
offset += len(downloads) offset += len(downloads)
page++ page++
@@ -129,13 +121,7 @@ func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download {
t.log.Warnf("Cannot unrestrict link %s: %v", link, err) t.log.Warnf("Cannot unrestrict link %s: %v", link, err)
return nil return nil
} }
if ret != nil && ret.Link != "" { if ret != nil && ret.Link != "" && ret.Filename != "" {
if strings.Contains(ret.Download, "download.real-debrid.") {
prefHost := t.Config.GetRandomPreferredHost()
if prefHost != "" {
ret.Download = replaceHostInURL(ret.Download, prefHost)
}
}
t.cacheDownload(ret) t.cacheDownload(ret)
} }
return ret return ret

View File

@@ -109,7 +109,7 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host
} }
var dialer proxy.Dialer = &net.Dialer{ var dialer proxy.Dialer = &net.Dialer{
Timeout: time.Duration(timeoutSecs) * time.Second, Timeout: time.Duration(timeoutSecs) * time.Second, // timeout to establish connection
} }
if proxyURLString := cfg.GetProxy(); proxyURLString != "" { if proxyURLString := cfg.GetProxy(); proxyURLString != "" {
proxyURL, err := url.Parse(proxyURLString) proxyURL, err := url.Parse(proxyURLString)