Delete in progress fixers

This commit is contained in:
Ben Sarmiento
2024-02-05 12:59:55 +01:00
parent eb9d91f8de
commit 58332a354b
4 changed files with 11 additions and 11 deletions

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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 {