Fix location of pref hosts injection
This commit is contained in:
@@ -2,6 +2,7 @@ package torrent
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -71,6 +72,12 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
}
|
||||
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.DownloadCache.Set(downloads[i].Link, &downloads[i])
|
||||
}
|
||||
}
|
||||
@@ -114,6 +121,12 @@ func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download {
|
||||
}
|
||||
ret := t.Api.UnrestrictUntilOk(link, t.Config.ShouldServeFromRclone())
|
||||
if ret != nil {
|
||||
if strings.Contains(ret.Download, "download.real-debrid.") {
|
||||
prefHost := t.Config.GetRandomPreferredHost()
|
||||
if prefHost != "" {
|
||||
ret.Download = replaceHostInURL(ret.Download, prefHost)
|
||||
}
|
||||
}
|
||||
t.DownloadCache.Set(link, ret)
|
||||
}
|
||||
return ret
|
||||
@@ -231,3 +244,12 @@ func (t *TorrentManager) deleteTorrentFile(torrentID string) {
|
||||
t.log.Warnf("Cannot delete file %s: %v", filePath, err)
|
||||
}
|
||||
}
|
||||
|
||||
func replaceHostInURL(inputURL string, newHost string) string {
|
||||
u, err := url.Parse(inputURL)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
u.Host = newHost
|
||||
return u.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user