From 8d4cdbbd1fa5ce7a6f595cc6633c42f8bd4861ca Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Fri, 26 Jan 2024 17:58:31 +0100 Subject: [PATCH] Remove GetRandomPreferredHost usage --- internal/config/types.go | 4 +++- internal/torrent/manager.go | 18 ++---------------- pkg/http/client.go | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/internal/config/types.go b/internal/config/types.go index 354ccd8..aea10e2 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -1,6 +1,8 @@ package config -import "math/rand" +import ( + "math/rand" +) type ConfigInterface interface { GetConfig() ZurgConfig diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 7f2492b..a51250b 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -78,15 +78,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w t.log.Fatalf("Cannot get downloads: %v", err) } for i := range downloads { - if !t.DownloadCache.Has(downloads[i].Link) { - 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]) - } + t.cacheDownload(&downloads[i]) } offset += len(downloads) page++ @@ -129,13 +121,7 @@ func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download { t.log.Warnf("Cannot unrestrict link %s: %v", link, err) return nil } - if ret != nil && ret.Link != "" { - if strings.Contains(ret.Download, "download.real-debrid.") { - prefHost := t.Config.GetRandomPreferredHost() - if prefHost != "" { - ret.Download = replaceHostInURL(ret.Download, prefHost) - } - } + if ret != nil && ret.Link != "" && ret.Filename != "" { t.cacheDownload(ret) } return ret diff --git a/pkg/http/client.go b/pkg/http/client.go index 3032151..d41e958 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -109,7 +109,7 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host } 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 != "" { proxyURL, err := url.Parse(proxyURLString)