Mount downloads directory
This commit is contained in:
@@ -26,6 +26,7 @@ type TorrentManager struct {
|
||||
Api *realdebrid.RealDebrid
|
||||
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
|
||||
DownloadCache cmap.ConcurrentMap[string, *realdebrid.Download]
|
||||
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
|
||||
allAccessKeys mapset.Set[string]
|
||||
latestState *LibraryState
|
||||
requiredVersion string
|
||||
@@ -59,6 +60,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
|
||||
// Fetch downloads
|
||||
t.DownloadCache = cmap.New[*realdebrid.Download]()
|
||||
t.DownloadMap = cmap.New[*realdebrid.Download]()
|
||||
if t.Config.EnableDownloadCache() {
|
||||
_ = t.workerPool.Submit(func() {
|
||||
page := 1
|
||||
@@ -76,7 +78,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
downloads[i].Download = replaceHostInURL(downloads[i].Download, prefHost)
|
||||
}
|
||||
}
|
||||
t.DownloadCache.Set(downloads[i].Link, &downloads[i])
|
||||
t.cacheDownload(&downloads[i])
|
||||
}
|
||||
}
|
||||
offset += len(downloads)
|
||||
@@ -114,18 +116,21 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
|
||||
// proxy
|
||||
func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download {
|
||||
if !strings.HasPrefix(link, "http") {
|
||||
return nil
|
||||
}
|
||||
if download, exists := t.DownloadCache.Get(link); exists {
|
||||
return download
|
||||
}
|
||||
ret := t.Api.UnrestrictUntilOk(link, t.Config.ShouldServeFromRclone())
|
||||
if ret != nil {
|
||||
ret, _ := t.Api.UnrestrictLink(link, t.Config.ShouldServeFromRclone())
|
||||
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)
|
||||
}
|
||||
}
|
||||
t.DownloadCache.Set(link, ret)
|
||||
t.cacheDownload(ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -251,3 +256,8 @@ func replaceHostInURL(inputURL string, newHost string) string {
|
||||
u.Host = newHost
|
||||
return u.String()
|
||||
}
|
||||
|
||||
func (t *TorrentManager) cacheDownload(ret *realdebrid.Download) {
|
||||
t.DownloadCache.Set(ret.Link, ret)
|
||||
t.DownloadMap.Set(ret.Filename, ret)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user