From b501b800dd254f46fadda7c5bdc495d391910bf2 Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Fri, 5 Jul 2024 16:47:36 +0200 Subject: [PATCH] Adjust logging for unplayable dir and assigning directories --- internal/torrent/manager.go | 4 ++-- internal/torrent/refresh.go | 17 ++++++++++++++--- internal/torrent/repair.go | 3 +-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 7074ecb..e0277da 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -103,14 +103,14 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w t.workerPool.Submit(func() { defer wg.Done() - // load *.zurgtorrent files + // initial load of existing *.zurgtorrent files allTorrents, _ := t.DirectoryMap.Get(INT_ALL) t.getTorrentFiles("data").Each(func(filePath string) bool { torrent := t.readTorrentFromFile(filePath) if torrent != nil { accessKey := t.GetKey(torrent) allTorrents.Set(accessKey, torrent) - t.assignDirectory(torrent, false) + t.assignDirectory(torrent, false, false) } return false }) diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index 31b827b..fb7feef 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -62,7 +62,7 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) { if !exists { allTorrents.Set(accessKey, torrent) t.writeTorrentToFile(torrent) - t.assignDirectory(torrent, !initialRun) + t.assignDirectory(torrent, !initialRun, true) } else if !mainTorrent.DownloadedIDs.ContainsOne(tInfo.ID) { forMerging = torrent } @@ -93,7 +93,7 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) { mainTorrent := t.mergeTorrents(existing, torrent) allTorrents.Set(accessKey, mainTorrent) t.writeTorrentToFile(mainTorrent) - t.assignDirectory(mainTorrent, !initialRun) + t.assignDirectory(mainTorrent, !initialRun, true) } // new torrents @@ -344,7 +344,7 @@ func (t *TorrentManager) mergeTorrents(existing, toMerge *Torrent) *Torrent { return mergedTorrent } -func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) { +func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool, outputLogs bool) { accessKey := t.GetKey(tor) t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) { @@ -372,6 +372,9 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) { }) if unplayable { + if outputLogs { + t.log.Warnf("No playable files for %s, moving to unplayable directory", accessKey) + } t.markAsUnplayable(tor, "no playable files") return } @@ -380,6 +383,7 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) { switch t.Config.GetVersion() { case "v1": updatedPaths := make([]string, 0) + dirs := make([]string, 0) configV1 := t.Config.(*config.ZurgConfigV1) for _, directories := range configV1.GetGroupMap() { for _, directory := range directories { @@ -387,6 +391,10 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) { listing, _ := t.DirectoryMap.Get(directory) listing.Set(accessKey, tor) + if directory != INT_ALL { + dirs = append(dirs, directory) + } + if triggerHook { updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey)) } @@ -397,6 +405,9 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) { if triggerHook { OnLibraryUpdateHook(updatedPaths, t.Config, t.log) } + if outputLogs { + t.log.Infof("Assigned %s to: %s", accessKey, strings.Join(dirs, ", ")) + } } } diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index 4f0811c..7937f48 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -445,7 +445,7 @@ func (t *TorrentManager) assignLinks(torrent *Torrent) bool { } } } else { - t.repairLog.Warnf("Torrent %s is rar'ed and we cannot repair it", t.GetKey(torrent)) + t.repairLog.Warnf("Torrent %s is rar'ed and we cannot repair it, moving to unplayable directory", t.GetKey(torrent)) t.markAsUnfixable(torrent, "rar'ed by RD") t.markAsUnplayable(torrent, "rar'ed by RD") torrent.State.Event(context.Background(), "mark_as_repaired") @@ -604,7 +604,6 @@ func (t *TorrentManager) canCapacityHandle() bool { } func (t *TorrentManager) markAsUnplayable(torrent *Torrent, reason string) { - t.repairLog.Debugf("Torrent %s is unplayable (reason: %s), moving to unplayable directory", t.GetKey(torrent), reason) // reassign to unplayable torrents directory t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) { if strings.HasPrefix(directory, "int__") {