Fix issue on downloads
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
@@ -33,6 +34,7 @@ type TorrentManager struct {
|
||||
workerPool *ants.Pool
|
||||
RefreshKillSwitch chan struct{}
|
||||
RepairKillSwitch chan struct{}
|
||||
RemountTrigger chan struct{}
|
||||
repairTrigger chan *Torrent
|
||||
repairSet mapset.Set[*Torrent]
|
||||
repairRunning bool
|
||||
@@ -49,9 +51,9 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
||||
Api: api,
|
||||
DirectoryMap: cmap.New[cmap.ConcurrentMap[string, *Torrent]](),
|
||||
DownloadCache: cmap.New[*realdebrid.Download](),
|
||||
DownloadMap: cmap.New[*realdebrid.Download](),
|
||||
RefreshKillSwitch: make(chan struct{}, 1),
|
||||
RepairKillSwitch: make(chan struct{}, 1),
|
||||
RemountTrigger: make(chan struct{}, 1),
|
||||
allAccessKeys: mapset.NewSet[string](),
|
||||
latestState: &LibraryState{},
|
||||
requiredVersion: "0.9.3-hotfix.4",
|
||||
@@ -60,11 +62,12 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
||||
}
|
||||
t.fixers = t.readFixersFromFile()
|
||||
t.initializeDirectories()
|
||||
t.mountDownloads()
|
||||
t.refreshTorrents()
|
||||
t.setNewLatestState(t.getCurrentState())
|
||||
t.StartRefreshJob()
|
||||
t.StartRepairJob()
|
||||
t.mountDownloads()
|
||||
t.StartDownloadsJob()
|
||||
|
||||
return t
|
||||
}
|
||||
@@ -85,7 +88,9 @@ func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download {
|
||||
}
|
||||
if ret != nil && ret.Link != "" && ret.Filename != "" {
|
||||
t.DownloadCache.Set(ret.Link, ret)
|
||||
t.DownloadMap.Set(ret.Filename, ret)
|
||||
if t.Config.EnableDownloadMount() {
|
||||
t.DownloadMap.Set(ret.Filename, ret)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -179,6 +184,7 @@ func (t *TorrentManager) mountDownloads() {
|
||||
if !t.Config.EnableDownloadMount() {
|
||||
return
|
||||
}
|
||||
t.DownloadMap = cmap.New[*realdebrid.Download]()
|
||||
_ = t.workerPool.Submit(func() {
|
||||
page := 1
|
||||
offset := 0
|
||||
@@ -196,7 +202,23 @@ func (t *TorrentManager) mountDownloads() {
|
||||
break
|
||||
}
|
||||
}
|
||||
t.log.Infof("Compiled into %d downloads", t.DownloadCache.Count())
|
||||
t.log.Infof("Compiled into %d downloads", t.DownloadMap.Count())
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TorrentManager) StartDownloadsJob() {
|
||||
_ = t.workerPool.Submit(func() {
|
||||
remountTicker := time.NewTicker(time.Duration(t.Config.GetDownloadsEveryMins()) * time.Minute)
|
||||
defer remountTicker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-remountTicker.C:
|
||||
t.mountDownloads()
|
||||
case <-t.RemountTrigger:
|
||||
t.mountDownloads()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user