Fixers and repairs

This commit is contained in:
Ben Sarmiento
2024-01-19 03:02:21 +01:00
parent c0b9fc8c55
commit 7b1e34c705
4 changed files with 35 additions and 17 deletions

View File

@@ -28,16 +28,30 @@ func (t *TorrentManager) RefreshTorrents() []string {
wg.Add(1)
_ = t.workerPool.Submit(func() {
defer wg.Done()
if instances[idx].Progress == 100 && t.onlyForRepair.Has(instances[idx].ID) {
torrent, _ := t.onlyForRepair.Get(instances[idx].ID)
if instances[idx].IsDone() && t.fixers.Has(instances[idx].ID) {
fixer := instances[idx]
torrent, _ := t.fixers.Pop(fixer.ID)
brokenFiles := getBrokenFiles(torrent)
info, err := t.redownloadTorrent(torrent, "")
if err == nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) {
t.Api.DeleteTorrent(instances[idx].ID)
t.onlyForRepair.Remove(instances[idx].ID)
if err == nil {
if info.IsDone() {
if t.isStillBroken(info, brokenFiles) {
t.log.Warnf("Fixer is done but torrent %s is still broken; let's keep the fixer", t.GetKey(torrent))
infoChan <- t.getMoreInfo(fixer)
return
} else {
t.log.Infof("Fixer resolved issues for torrent %s, broken files are repaired", t.GetKey(torrent))
}
} else {
t.log.Warnf("Torrent %s is still not done after redownload; likely the fixer did its job", t.GetKey(torrent))
}
t.Api.DeleteTorrent(fixer.ID) // delete the fixer
infoChan <- nil
return
} else {
t.log.Warnf("Cannot redownload torrent %s after fixer is done: %v", t.GetKey(torrent), err)
}
infoChan <- nil
} else {
} else if !t.fixers.Has(instances[idx].ID) {
infoChan <- t.getMoreInfo(instances[idx])
}
})
@@ -204,7 +218,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
}
torrent.DownloadedIDs = mapset.NewSet[string]()
torrent.InProgressIDs = mapset.NewSet[string]()
if info.Progress == 100 {
if info.IsDone() {
torrent.DownloadedIDs.Add(info.ID)
} else {
torrent.InProgressIDs.Add(info.ID)