Repair adjustments 2
This commit is contained in:
@@ -211,16 +211,21 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
|
||||
oldTorrentIDs := torrent.DownloadedIDs.Union(torrent.InProgressIDs).ToSlice()
|
||||
|
||||
newlyDownloadedIds := make([]string, 0)
|
||||
group := make([]*File, 0)
|
||||
for _, file := range brokenFiles {
|
||||
group = append(group, file)
|
||||
if len(group) == 100 {
|
||||
if len(group) >= 200 {
|
||||
brokenFileIDs := getFileIDs(group)
|
||||
_, err := t.redownloadTorrent(torrent, brokenFileIDs)
|
||||
redownloadedInfo, err := t.redownloadTorrent(torrent, brokenFileIDs)
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err.Error())
|
||||
for _, newId := range newlyDownloadedIds {
|
||||
t.registerFixer(newId, "download_failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
newlyDownloadedIds = append(newlyDownloadedIds, redownloadedInfo.ID)
|
||||
group = make([]*File, 0)
|
||||
}
|
||||
}
|
||||
@@ -230,12 +235,15 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
_, err := t.redownloadTorrent(torrent, brokenFileIDs)
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err.Error())
|
||||
for _, newId := range newlyDownloadedIds {
|
||||
t.registerFixer(newId, "download_failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, oldId := range oldTorrentIDs {
|
||||
t.fixerAddCommand(oldId, "replaced")
|
||||
t.registerFixer(oldId, "replaced")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,51 +377,59 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
newTorrentID := resp.ID
|
||||
|
||||
// sleep for 1 second to let RD process the magnet
|
||||
time.Sleep(1 * time.Second)
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
// select files
|
||||
err = t.Api.SelectTorrentFiles(newTorrentID, selection)
|
||||
if err != nil {
|
||||
t.fixerAddCommand(newTorrentID, "download_failed")
|
||||
return nil, fmt.Errorf("cannot start redownloading: %v", err)
|
||||
}
|
||||
var info *realdebrid.TorrentInfo
|
||||
for {
|
||||
// select files
|
||||
err = t.Api.SelectTorrentFiles(newTorrentID, selection)
|
||||
if err != nil {
|
||||
t.registerFixer(newTorrentID, "download_failed")
|
||||
return nil, fmt.Errorf("cannot start redownloading: %v", err)
|
||||
}
|
||||
// sleep for 5 second to let RD process the magnet
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
// sleep for 1 second to let RD process the magnet
|
||||
time.Sleep(1 * time.Second)
|
||||
// see if the torrent is ready
|
||||
info, err = t.Api.GetTorrentInfo(newTorrentID)
|
||||
if err != nil {
|
||||
t.registerFixer(newTorrentID, "download_failed")
|
||||
return nil, fmt.Errorf("cannot get info on redownloaded torrent %s (id=%s) : %v", t.GetKey(torrent), newTorrentID, err)
|
||||
}
|
||||
|
||||
// see if the torrent is ready
|
||||
info, err := t.Api.GetTorrentInfo(newTorrentID)
|
||||
if err != nil {
|
||||
t.fixerAddCommand(newTorrentID, "download_failed")
|
||||
return nil, fmt.Errorf("cannot get info on redownloaded torrent %s (id=%s) : %v", t.GetKey(torrent), newTorrentID, err)
|
||||
if info.Status != "magnet_conversion" && info.Status != "waiting_files_selection" {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// documented status: magnet_error, magnet_conversion, waiting_files_selection, queued, downloading, downloaded, error, virus, compressing, uploading, dead
|
||||
okStatuses := []string{"downloading", "downloaded", "uploading"}
|
||||
// not compressing because we need playable files
|
||||
isOkStatus := false
|
||||
okStatuses := []string{"downloading", "downloaded", "uploading", "queued", "compressing"}
|
||||
// not compressing because we need playable files
|
||||
for _, status := range okStatuses {
|
||||
if info.Status == status {
|
||||
isOkStatus = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !isOkStatus {
|
||||
t.fixerAddCommand(info.ID, "download_failed")
|
||||
return nil, fmt.Errorf("the redownloaded torrent %s (id=%s) is in a non-OK state: %s", t.GetKey(torrent), info.ID, info.Status)
|
||||
t.registerFixer(info.ID, "download_failed")
|
||||
return nil, fmt.Errorf("the redownloaded torrent %s is in a non-OK state: %s", t.GetKey(torrent), info.Status)
|
||||
}
|
||||
|
||||
// check if incorrect number of links
|
||||
selectionCount := len(strings.Split(selection, ","))
|
||||
if info.Progress == 100 && len(info.Links) != selectionCount {
|
||||
t.fixerAddCommand(newTorrentID, "download_failed")
|
||||
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)
|
||||
t.registerFixer(newTorrentID, "download_failed")
|
||||
return nil, fmt.Errorf("torrent %s only got %d links but we need %d", t.GetKey(torrent), len(info.Links), selectionCount)
|
||||
}
|
||||
|
||||
t.log.Infof("Redownloading torrent %s successful (id=%s, progress=%d)", t.GetKey(torrent), info.ID, info.Progress)
|
||||
for _, id := range oldTorrentIDs {
|
||||
t.fixerAddCommand(id, "replaced")
|
||||
t.registerFixer(id, "replaced")
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user