Repair fixes
This commit is contained in:
@@ -48,7 +48,7 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TorrentManager) repair(torrent *Torrent) {
|
func (t *TorrentManager) repair(torrent *Torrent) {
|
||||||
if torrent.AllInProgress() {
|
if torrent.AnyInProgress() {
|
||||||
t.log.Infof("Torrent %s is in progress, skipping repair until download is done", torrent.AccessKey)
|
t.log.Infof("Torrent %s is in progress, skipping repair until download is done", torrent.AccessKey)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -59,10 +59,17 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// first solution: reinsert with same selection
|
expiredLinkTolerance := 24 * time.Hour
|
||||||
if t.reinsertTorrent(torrent, "") {
|
if torrent.OlderThanDuration(expiredLinkTolerance) {
|
||||||
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
|
// first solution: reinsert with same selection
|
||||||
return
|
if t.reinsertTorrent(torrent, "") {
|
||||||
|
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
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())
|
||||||
}
|
}
|
||||||
|
|
||||||
// second solution: add only the missing files
|
// second solution: add only the missing files
|
||||||
@@ -103,9 +110,12 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string) bool {
|
func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string) bool {
|
||||||
|
oldTorrentIDs := make([]string, 0)
|
||||||
// missing files means missing links
|
// missing files means missing links
|
||||||
// if missingFiles is not provided
|
// if missingFiles is not provided
|
||||||
if missingFiles == "" {
|
if missingFiles == "" {
|
||||||
|
// only replace the torrent if we are reinserting all files
|
||||||
|
oldTorrentIDs = torrent.DownloadedIDs.List()
|
||||||
tmpSelection := ""
|
tmpSelection := ""
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
tmpSelection += fmt.Sprintf("%d,", file.ID) // select all files
|
tmpSelection += fmt.Sprintf("%d,", file.ID) // select all files
|
||||||
@@ -151,6 +161,9 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string)
|
|||||||
|
|
||||||
if info.Progress != 100 {
|
if info.Progress != 100 {
|
||||||
t.log.Infof("Torrent id=%s is not cached anymore so we have to wait until completion (this should fix the issue already)", info.ID)
|
t.log.Infof("Torrent id=%s is not cached anymore so we have to wait until completion (this should fix the issue already)", info.ID)
|
||||||
|
for _, id := range oldTorrentIDs {
|
||||||
|
t.Api.DeleteTorrent(id)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +175,9 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.log.Infof("Repair successful id=%s", newTorrentID)
|
t.log.Infof("Repair successful id=%s", newTorrentID)
|
||||||
|
for _, id := range oldTorrentIDs {
|
||||||
|
t.Api.DeleteTorrent(id)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package torrent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
stdjson "encoding/json"
|
stdjson "encoding/json"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
@@ -113,6 +115,15 @@ func (t *Torrent) ComputeTotalSize() int64 {
|
|||||||
return totalSize
|
return totalSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
realdebrid.File
|
realdebrid.File
|
||||||
Added string `json:"Added"`
|
Added string `json:"Added"`
|
||||||
|
|||||||
Reference in New Issue
Block a user