From f977abc0526199404f32ca9c1aaef69ef45959fb Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Tue, 4 Jun 2024 23:58:56 +0200 Subject: [PATCH] Fixes on merge behavior; remove downloads cap --- internal/config/types.go | 18 +++++------------- internal/handlers/home.go | 5 ----- internal/torrent/manager.go | 11 +++++------ internal/torrent/refresh.go | 4 +--- pkg/realdebrid/api.go | 12 ++++-------- 5 files changed, 15 insertions(+), 35 deletions(-) diff --git a/internal/config/types.go b/internal/config/types.go index b1aa607..04856fc 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -30,7 +30,6 @@ type ConfigInterface interface { GetRateLimitSleepSecs() int ShouldDeleteRarFiles() bool GetDownloadsEveryMins() int - GetDownloadsLimit() int GetDumpTorrentsEveryMins() int GetPlayableExtensions() []string GetTorrentsCount() int @@ -117,35 +116,28 @@ func (z *ZurgConfig) GetNumOfWorkers() int { func (z *ZurgConfig) GetRefreshEverySecs() int { if z.RefreshEverySecs == 0 { - return 60 + return 15 } return z.RefreshEverySecs } func (z *ZurgConfig) GetRepairEveryMins() int { if z.RepairEveryMins == 0 { - return 60 + return 60 // 1 hour } return z.RepairEveryMins } func (z *ZurgConfig) GetDownloadsEveryMins() int { if z.DownloadsEveryMins == 0 { - return 1440 + return 720 // 12 hours } return z.DownloadsEveryMins } -func (z *ZurgConfig) GetDownloadsLimit() int { - if z.DownloadsLimit == 0 { - return 10000 - } - return z.DownloadsLimit -} - func (z *ZurgConfig) GetDumpTorrentsEveryMins() int { if z.DumpTorrentsEveryMins == 0 { - return 1440 + return 1440 // 1 day } return z.DumpTorrentsEveryMins } @@ -226,7 +218,7 @@ func (z *ZurgConfig) GetPlayableExtensions() []string { func (z *ZurgConfig) GetTorrentsCount() int { if z.TorrentsCount == 0 { - return 100 + return 250 } return z.TorrentsCount } diff --git a/internal/handlers/home.go b/internal/handlers/home.go index 9634e9a..a86b8fb 100644 --- a/internal/handlers/home.go +++ b/internal/handlers/home.go @@ -222,10 +222,6 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) { Refresh Download Mount Every... %d mins - - Get downloads limit - %d items - Dump Torrents Every... %d mins @@ -336,7 +332,6 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) { response.Config.GetTorrentsCount(), response.Config.GetDownloadTimeoutSecs(), response.Config.GetDownloadsEveryMins(), - response.Config.GetDownloadsLimit(), response.Config.GetDumpTorrentsEveryMins(), response.Config.GetRateLimitSleepSecs(), response.Config.GetRetriesUntilFailed(), diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index dcb12eb..f9fb19c 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -342,12 +342,10 @@ func (t *TorrentManager) mountNewDownloads() { downloads := t.api.GetDownloads() for i := range downloads { isRealDebrid := strings.HasPrefix(downloads[i].Link, "https://real-debrid.com/d/") - if isRealDebrid && !t.UnrestrictMap.Has(downloads[i].Link[0:39]) { - t.UnrestrictMap.Set(downloads[i].Link[0:39], &downloads[i]) - } else if !isRealDebrid { - if !t.UnrestrictMap.Has(downloads[i].Link) { - t.UnrestrictMap.Set(downloads[i].Link, &downloads[i]) - } + if isRealDebrid { + t.UnrestrictMap.SetIfAbsent(downloads[i].Link[0:39], &downloads[i]) + } else { + t.UnrestrictMap.SetIfAbsent(downloads[i].Link, &downloads[i]) filename := filepath.Base(downloads[i].Filename) t.DownloadMap.Set(filename, &downloads[i]) } @@ -362,6 +360,7 @@ func (t *TorrentManager) StartDownloadsJob() { for { select { case <-remountTicker.C: + t.DownloadMap.Clear() t.mountNewDownloads() case <-t.RemountTrigger: t.DownloadMap.Clear() diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index 9908c36..28e8530 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -296,9 +296,7 @@ func (t *TorrentManager) mergeTorrents(existing, toMerge *Torrent) *Torrent { // selected files mergedTorrent.SelectedFiles = cmap.New[*File]() newer.SelectedFiles.IterCb(func(key string, file *File) { - if f, ok := mergedTorrent.SelectedFiles.Get(key); !ok || !f.State.Is("ok_file") { - mergedTorrent.SelectedFiles.Set(key, file) - } + mergedTorrent.SelectedFiles.SetIfAbsent(key, file) }) older.SelectedFiles.IterCb(func(key string, file *File) { mediaInfo := file.MediaInfo diff --git a/pkg/realdebrid/api.go b/pkg/realdebrid/api.go index a8e7505..31584a4 100644 --- a/pkg/realdebrid/api.go +++ b/pkg/realdebrid/api.go @@ -194,6 +194,7 @@ func (rd *RealDebrid) GetTorrents(onlyOne bool) ([]Torrent, int, error) { for i := 0; i < maxParallelThreads; i++ { res := <-allResults if res.err != nil { + rd.log.Warnf("Ignoring error when fetching torrents: %v", res.err) continue } allTorrents = append(allTorrents, res.torrents...) @@ -362,8 +363,6 @@ func (rd *RealDebrid) GetDownloads() []Download { return nil } - maxItems := rd.cfg.GetDownloadsLimit() - // reset allDownloads allDownloads := []Download{} page := 1 @@ -401,18 +400,15 @@ func (rd *RealDebrid) GetDownloads() []Download { res := <-allResults err := <-errChan if err != nil { - return allDownloads + rd.log.Warnf("Ignoring error when fetching downloads: %v", err) + continue } allDownloads = append(allDownloads, res...) } rd.log.Debugf("Got %d/%d downloads", len(allDownloads), totalCount) - if len(allDownloads) >= totalCount || page >= maxPages || len(allDownloads) >= maxItems { - if len(allDownloads) > maxItems { - rd.log.Debugf("Capping it to %d downloads", len(allDownloads)) - allDownloads = allDownloads[:maxItems] - } + if len(allDownloads) >= totalCount || page >= maxPages { break }