From 62bfa375ca297089fef56b762da46087735b8190 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Fri, 8 Dec 2023 14:14:58 +0100 Subject: [PATCH] Unrepairable hotfix --- internal/torrent/refresh.go | 3 +-- internal/torrent/repair.go | 18 +++++++++++------- internal/torrent/types.go | 2 -- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index 78d14aa..dffedc0 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -77,8 +77,6 @@ func (t *TorrentManager) RefreshTorrents() []string { return true }) - t.SetNewLatestState(t.getCurrentState()) - return updatedPaths } @@ -98,6 +96,7 @@ func (t *TorrentManager) startRefreshJob() { if t.latestState.equal(checksum) { continue } + t.SetNewLatestState(checksum) t.log.Infof("Detected changes! Refreshing %d torrents", checksum.TotalCount) updatedPaths := t.RefreshTorrents() diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index 1120d00..6bf4eb1 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -7,6 +7,8 @@ import ( "time" ) +const EXPIRED_LINK_TOLERANCE_HOURS = 24 + func (t *TorrentManager) RepairAll() { _ = t.repairWorker.Submit(func() { t.repairAll() @@ -53,8 +55,7 @@ func (t *TorrentManager) repair(torrent *Torrent) { return } - expiredLinkTolerance := 24 * time.Hour - if torrent.OlderThanDuration(expiredLinkTolerance) { + if torrent.OlderThanDuration(EXPIRED_LINK_TOLERANCE_HOURS * time.Hour) { // first solution: reinsert with same selection if t.reinsertTorrent(torrent, "") { t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey) @@ -63,7 +64,7 @@ func (t *TorrentManager) repair(torrent *Torrent) { t.log.Warn("Failed to repair by reinserting torrent") } } else { - t.log.Infof("Torrent %s is not older than %d hours to be repaired by reinsertion, skipping", torrent.AccessKey, expiredLinkTolerance.Hours()) + t.log.Infof("Torrent %s is not older than %d hours to be repaired by reinsertion, skipping", torrent.AccessKey, EXPIRED_LINK_TOLERANCE_HOURS) } // second solution: add only the missing files @@ -74,10 +75,13 @@ func (t *TorrentManager) repair(torrent *Torrent) { } }) - // if we download a single file, it will be named differently - // so we need to download 1 extra file to preserve the name - // this is only relevant if we enable retain_rd_torrent_name - if len(missingFiles) == 1 && torrent.SelectedFiles.Count() > 1 { + if len(missingFiles) == 1 && torrent.SelectedFiles.Count() == 1 { + t.log.Warnf("Torrent %s is unrepairable, the lone file is expired but still cached in Real-Debrid", torrent.AccessKey) + return + } else if len(missingFiles) == 1 && torrent.SelectedFiles.Count() > 1 { + // if we download a single file, it will be named differently + // so we need to download 1 extra file to preserve the name + // this is only relevant if we enable retain_rd_torrent_name // add the first file link encountered with a prefix of http for _, file := range torrent.SelectedFiles.Items() { if strings.HasPrefix(file.Link, "http") { diff --git a/internal/torrent/types.go b/internal/torrent/types.go index ddd8aaf..3909769 100644 --- a/internal/torrent/types.go +++ b/internal/torrent/types.go @@ -2,7 +2,6 @@ package torrent import ( stdjson "encoding/json" - "fmt" "strings" "time" @@ -128,7 +127,6 @@ func (t *Torrent) ComputeBiggestFileSize() int64 { func (t *Torrent) OlderThanDuration(duration time.Duration) bool { latestAdded, err := time.Parse(time.RFC3339, t.LatestAdded) if err != nil { - fmt.Println("Error parsing time:", err) return false } return time.Since(latestAdded) > duration