From 845a01d7f3dced2236492dd8c8383d2e4d82b965 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Thu, 7 Dec 2023 15:58:22 +0100 Subject: [PATCH] Add library update hook on repair all --- internal/torrent/delete.go | 2 +- internal/torrent/hooks.go | 2 +- internal/torrent/refresh.go | 8 ++++++-- internal/torrent/repair.go | 14 +++++++++----- pkg/realdebrid/api.go | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/internal/torrent/delete.go b/internal/torrent/delete.go index 374e647..169c9d6 100644 --- a/internal/torrent/delete.go +++ b/internal/torrent/delete.go @@ -26,7 +26,7 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) { infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE) if torrent, ok := allTorrents.Get(accessKey); ok { torrent.DownloadedIDs.Each(func(id string) bool { - t.log.Infof("Deleting torrent %s %s in RD", id, accessKey) + t.log.Debugf("Deleting torrent %s %s in RD", id, accessKey) t.Api.DeleteTorrent(id) infoCache.Remove(id) t.deleteTorrentFile(id) diff --git a/internal/torrent/hooks.go b/internal/torrent/hooks.go index 69f5a37..7a973a6 100644 --- a/internal/torrent/hooks.go +++ b/internal/torrent/hooks.go @@ -43,6 +43,6 @@ func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *log return } if output != "" { - log.Infof("Output of hook on_library_update:\n%s", output) + log.Debugf("Output of hook on_library_update:\n%s", output) } } diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index f4ea40e..78d14aa 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -31,7 +31,7 @@ func (t *TorrentManager) RefreshTorrents() []string { } wg.Wait() close(infoChan) - t.log.Infof("Fetched info for %d torrents", len(instances)) + t.log.Debugf("Fetched info for %d torrents", len(instances)) freshKeys := set.NewStringSet() allTorrents, _ := t.DirectoryMap.Get(INT_ALL) @@ -55,6 +55,7 @@ func (t *TorrentManager) RefreshTorrents() []string { strset.Difference(freshKeys, t.allAccessKeys).Each(func(accessKey string) bool { // assign to directories tor, _ := allTorrents.Get(accessKey) + var directories []string t.assignedDirectoryCb(tor, func(directory string) { if strings.HasPrefix(directory, "int__") { return @@ -62,8 +63,11 @@ func (t *TorrentManager) RefreshTorrents() []string { torrents, _ := t.DirectoryMap.Get(directory) torrents.Set(accessKey, tor) updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey)) + if directory != "__all__" { + directories = append(directories, directory) + } }) - t.log.Infof("Added %s to the library", accessKey) + t.log.Debugf("Added %s to %v", accessKey, directories) t.allAccessKeys.Add(accessKey) return true }) diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index 74f3e47..40ae569 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -9,9 +9,8 @@ import ( func (t *TorrentManager) RepairAll() { _ = t.repairWorker.Submit(func() { - t.log.Info("Checking for torrents to repair") t.repairAll() - t.log.Info("Finished checking for torrents to repair") + t.log.Debug("Finished repairing all torrents") }) } @@ -27,10 +26,16 @@ func (t *TorrentManager) repairAll() { } }) t.log.Debugf("Found %d torrents to repair", len(toRepair)) + var updatedPaths []string for i := range toRepair { - t.log.Infof("Repairing %s", toRepair[i].AccessKey) - t.repair(toRepair[i]) + torrent := toRepair[i] + t.log.Infof("Repairing %s", torrent.AccessKey) + t.repair(torrent) + t.assignedDirectoryCb(torrent, func(directory string) { + updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, torrent.AccessKey)) + }) } + t.TriggerHookOnLibraryUpdate(updatedPaths) } func (t *TorrentManager) Repair(torrent *Torrent) { @@ -205,7 +210,6 @@ func (t *TorrentManager) canCapacityHandle() bool { } if count.DownloadingCount < count.MaxNumberOfTorrents { - // t.log.Infof("We can still add a new torrent, we have capacity for %d more", count.MaxNumberOfTorrents-count.DownloadingCount) return true } diff --git a/pkg/realdebrid/api.go b/pkg/realdebrid/api.go index 674c738..e60e5a2 100644 --- a/pkg/realdebrid/api.go +++ b/pkg/realdebrid/api.go @@ -56,7 +56,7 @@ func (rd *RealDebrid) UnrestrictCheck(link string) (*Download, error) { return nil, err } - rd.log.Info("Link %s is streamable? %v", response.Streamable) + rd.log.Debugf("Link %s is streamable? %v", response.Streamable) return &response, nil }