From 58332a354b04e27afe5c38b42ade74cdce878a15 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Mon, 5 Feb 2024 12:59:55 +0100 Subject: [PATCH] Delete in progress fixers --- internal/torrent/refresh.go | 2 +- internal/torrent/repair.go | 12 ++++++------ pkg/http/client.go | 6 +++--- pkg/realdebrid/types.go | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index af6276f..2bf1605 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -214,7 +214,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent { } torrent.DownloadedIDs = mapset.NewSet[string]() torrent.InProgressIDs = mapset.NewSet[string]() - if info.IsDone() { + if info.Progress == 100 { torrent.DownloadedIDs.Add(info.ID) } else { torrent.InProgressIDs.Add(info.ID) diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index 89dd4cd..15cab09 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -106,7 +106,6 @@ func (t *TorrentManager) repairAll(torrent *Torrent) { } }) if brokenFileIDs.Cardinality() > 0 { - t.log.Debugf("Torrent %s has %d broken files (ids=%v), adding to repair list", t.GetKey(torrent), brokenFileIDs.Cardinality(), brokenFileIDs.ToSlice()) toRepair.Add(torrent) return } @@ -166,18 +165,19 @@ func (t *TorrentManager) repair(torrent *Torrent) { // get all broken files brokenFiles := getBrokenFiles(torrent) - t.log.Debugf("Torrent %s has %d broken files (total is %d)", t.GetKey(torrent), len(brokenFiles), torrent.SelectedFiles.Count()) brokenFileIDs := getFileIDs(brokenFiles) + t.log.Debugf("Torrent %s has %d broken files (ids=%s; total is %d), repairing by redownloading", t.GetKey(torrent), len(brokenFiles), brokenFileIDs, torrent.SelectedFiles.Count()) // first step: redownload the whole torrent - t.log.Debugf("Repairing torrent %s by redownloading", t.GetKey(torrent)) info, err := t.redownloadTorrent(torrent, "") // reinsert the torrent, passing "" if err != nil { t.log.Warnf("Cannot repair torrent %s by redownloading (error=%s)", t.GetKey(torrent), err.Error()) } else if info != nil && info.Progress != 100 { - t.log.Infof("Torrent %s is still in progress after redownloading but it should be repaired once done", t.GetKey(torrent)) + torrent.InProgressIDs.Add(info.ID) + t.saveTorrentChangesToDisk(torrent, nil) + t.log.Infof("Torrent %s (files=%s) is still in progress after redownloading but it should be repaired once done", t.GetKey(torrent), brokenFileIDs) return - } else if info != nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) { + } else if info != nil && info.Progress == 100 && !t.isStillBroken(info, brokenFiles) { selectedFiles := getSelectedFiles(info) torrent.SelectedFiles.IterCb(func(_ string, oldFile *File) { for _, newFile := range selectedFiles { @@ -190,7 +190,7 @@ func (t *TorrentManager) repair(torrent *Torrent) { }) torrent.DownloadedIDs.Add(info.ID) t.saveTorrentChangesToDisk(torrent, nil) - t.log.Infof("Successfully repaired torrent %s by redownloading", t.GetKey(torrent)) + t.log.Infof("Successfully repaired torrent %s (files=%s) by redownloading", t.GetKey(torrent), brokenFileIDs) return } diff --git a/pkg/http/client.go b/pkg/http/client.go index 2500fcb..fc486d8 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -176,6 +176,9 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) { break } } + if err != nil && strings.Contains(err.Error(), "timeout") && req.Host == "api.real-debrid.com" && !strings.HasSuffix(req.URL.Path, "unrestrict/link") { + r.log.Warnf("Adjust your API timeout settings, request to %s timed out", req.URL.String()) + } return resp, err } @@ -249,9 +252,6 @@ func (r *HTTPClient) shouldRetry(resp *http.Response, reqHasRangeHeader bool, er } } if err != nil && strings.Contains(err.Error(), "timeout") { - if resp.Request.URL.Host == "api.real-debrid.com" && !strings.Contains(resp.Request.URL.Path, "unrestrict/") { - r.log.Warnf("Request timed out, adjust the timeout value in the config") - } return 1 } if resp != nil { diff --git a/pkg/realdebrid/types.go b/pkg/realdebrid/types.go index 184bf4f..11ca99d 100644 --- a/pkg/realdebrid/types.go +++ b/pkg/realdebrid/types.go @@ -86,7 +86,7 @@ type TorrentInfo struct { Files []File `json:"files"` } -func (i *TorrentInfo) IsDone() bool { +func (i *TorrentInfo) IsComplete() bool { selectedCount := 0 for _, file := range i.Files { if file.Selected == 1 {