Fix the fixer
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||||
cmap "github.com/orcaman/concurrent-map/v2"
|
cmap "github.com/orcaman/concurrent-map/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,36 +21,43 @@ func (t *TorrentManager) fixerAddCommand(trigger, command string) {
|
|||||||
t.writeFixersToFile()
|
t.writeFixersToFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TorrentManager) handleFixers() {
|
func (t *TorrentManager) handleFixers(instances []realdebrid.Torrent) {
|
||||||
var toDelete []string
|
var toDelete []string
|
||||||
|
var toRedownload []*Torrent
|
||||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
for _, instance := range instances {
|
||||||
infoCache.IterCb(func(id string, torrent *Torrent) {
|
id := instance.ID
|
||||||
if !t.fixers.Has(id) || torrent.AnyInProgress() {
|
if !t.fixers.Has(id) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
command, _ := t.fixers.Pop(id) // delete the fixer if it's done
|
command, _ := t.fixers.Pop(id) // delete the fixer if it's done
|
||||||
switch command {
|
switch command {
|
||||||
case "replaced": // id is old torrent id
|
case "replaced": // id is old torrent id
|
||||||
t.log.Debugf("Deleting old id=%s because it's redundant to fixed %s ", id, t.GetKey(torrent))
|
t.log.Debugf("Deleting old id=%s because it's redundant to fixed %s ", id, instance.Name)
|
||||||
toDelete = append(toDelete, id)
|
toDelete = append(toDelete, id)
|
||||||
case "download_failed": // id is failed fixer id
|
case "download_failed": // id is failed fixer id
|
||||||
t.log.Debugf("Deleting failed fixer id=%s of torrent %s", id, t.GetKey(torrent))
|
t.log.Debugf("Deleting failed fixer id=%s of torrent %s", id, instance.Name)
|
||||||
toDelete = append(toDelete, id)
|
toDelete = append(toDelete, id)
|
||||||
case "repaired": // id is fixer id
|
case "repaired": // this torrent contains broken files
|
||||||
|
if instance.Progress != 100 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
torrent := t.getMoreInfo(instance)
|
||||||
t.log.Debugf("Repairing torrent %s again now that fixer id=%s is done", t.GetKey(torrent), id)
|
t.log.Debugf("Repairing torrent %s again now that fixer id=%s is done", t.GetKey(torrent), id)
|
||||||
repairMe, _ := allTorrents.Get(t.GetKey(torrent))
|
repairMe, _ := allTorrents.Get(t.GetKey(torrent))
|
||||||
repairMe.DownloadedIDs.Remove(id)
|
toRedownload = append(toRedownload, repairMe)
|
||||||
toDelete = append(toDelete, id)
|
|
||||||
t.TriggerRepair(repairMe)
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||||
for _, id := range toDelete {
|
for _, id := range toDelete {
|
||||||
t.Api.DeleteTorrent(id)
|
t.Api.DeleteTorrent(id)
|
||||||
infoCache.Remove(id)
|
infoCache.Remove(id)
|
||||||
t.deleteTorrentFile(id)
|
t.deleteTorrentFile(id)
|
||||||
}
|
}
|
||||||
|
for _, torrent := range toRedownload {
|
||||||
|
t.redownloadTorrent(torrent, "")
|
||||||
|
}
|
||||||
// remove expired fixers
|
// remove expired fixers
|
||||||
var expired []string
|
var expired []string
|
||||||
t.fixers.IterCb(func(trigger string, command string) {
|
t.fixers.IterCb(func(trigger string, command string) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func (t *TorrentManager) refreshTorrents() []string {
|
|||||||
|
|
||||||
if t.Config.EnableRepair() {
|
if t.Config.EnableRepair() {
|
||||||
t.workerPool.Submit(func() {
|
t.workerPool.Submit(func() {
|
||||||
t.handleFixers()
|
t.handleFixers(instances)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
|||||||
return nil, fmt.Errorf("it did not fix the issue for %s (id=%s), only got %d files but we need %d, undoing", t.GetKey(torrent), info.ID, len(info.Links), selectionCount)
|
return nil, fmt.Errorf("it did not fix the issue for %s (id=%s), only got %d files but we need %d, undoing", t.GetKey(torrent), info.ID, len(info.Links), selectionCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// looks like it's fixed even if it's not done yet
|
t.log.Infof("Redownloading torrent %s successful (progress=%d)", t.GetKey(torrent), info.Progress)
|
||||||
for _, id := range oldTorrentIDs {
|
for _, id := range oldTorrentIDs {
|
||||||
t.fixerAddCommand(id, "replaced")
|
t.fixerAddCommand(id, "replaced")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user