Handle differently if all are broken

This commit is contained in:
Ben Sarmiento
2024-02-17 04:22:50 +01:00
parent 20d46d9f2b
commit 041e02816b
2 changed files with 78 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ package torrent
import (
"io"
"os"
"strings"
"github.com/debridmediamanager/zurg/pkg/realdebrid"
cmap "github.com/orcaman/concurrent-map/v2"
@@ -36,19 +37,51 @@ func (t *TorrentManager) processFixers(instances []realdebrid.Torrent) {
case "replaced": // id is old torrent id
t.log.Debugf("Deleting old id=%s because it's redundant to fixed %s ", id, instance.Name)
toDelete = append(toDelete, id)
continue
case "download_failed": // id is failed fixer id
t.log.Debugf("Deleting failed fixer id=%s of torrent %s", id, instance.Name)
toDelete = append(toDelete, id)
continue
case "repaired": // this torrent contains broken files
if instance.Progress != 100 {
t.fixers.Set(id, "repaired") // requeue the fixer
t.fixers.Set(id, command) // requeue the fixer
continue
}
torrent := t.getMoreInfo(instance)
t.log.Debugf("Repairing torrent %s again now that fixer id=%s is done", t.GetKey(torrent), id)
repairMe, _ := allTorrents.Get(t.GetKey(torrent))
toRedownload = append(toRedownload, repairMe)
toDelete = append(toDelete, id)
continue
}
// a new case: repaired_with:<id>
if strings.HasPrefix(command, "repaired_with:") {
if instance.Progress != 100 {
t.fixers.Set(id, command) // requeue the fixer
continue
}
otherId := strings.TrimPrefix(command, "repaired_with:")
for _, instance := range instances {
if instance.ID == otherId {
if instance.Progress != 100 {
t.fixers.Set(id, command) // requeue the fixer
break
}
torrent := t.getMoreInfo(instance)
t.log.Debugf("Repairing torrent %s again now that fixers ids=%s and %s are done", t.GetKey(torrent), id, otherId)
repairMe, _ := allTorrents.Get(t.GetKey(torrent))
toRedownload = append(toRedownload, repairMe)
toDelete = append(toDelete, id, otherId)
break
}
}
continue
}
}