assigned links

This commit is contained in:
Ben Sarmiento
2024-01-12 01:12:34 +01:00
parent cc37a92d75
commit ebab40d3e6
7 changed files with 71 additions and 57 deletions

View File

@@ -113,7 +113,7 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
return file.Link == link
})
})
t.writeTorrentToFile(id, info, false)
t.writeTorrentToFile(id, info)
return false
})
_ = t.workerPool.Submit(func() {
@@ -129,7 +129,6 @@ func (t *TorrentManager) repair(torrent *Torrent) {
t.log.Infof("Torrent %s is in progress, skipping repair until download is done", t.GetKey(torrent))
return
}
torrent.InProgressIDs.Add(REPAIR_SEMAPHORE)
proceed := t.canCapacityHandle() // blocks for approx 45 minutes if active torrents are full
@@ -158,28 +157,33 @@ func (t *TorrentManager) repair(torrent *Torrent) {
assignedCount := 0
rarCount := 0
unassignedDownloads := make([]*realdebrid.Download, 0)
assignedLinks := make([]string, 0)
torrent.UnassignedLinks.Each(func(link string) bool {
unrestrict := t.UnrestrictUntilOk(link)
if unrestrict != nil {
// assign to a selected file
assigned := false
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
// if strings.HasSuffix(file.Path, unrestrict.Filename) {
if file.Bytes == unrestrict.Filesize {
file.Link = unrestrict.Link
assigned = true
assignedCount++
}
})
if !assigned {
if strings.HasSuffix(unrestrict.Filename, ".rar") {
rarCount++
}
unassignedDownloads = append(unassignedDownloads, unrestrict)
if unrestrict == nil {
return false
}
// assign to a selected file
assigned := false
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
// if strings.HasSuffix(file.Path, unrestrict.Filename) {
if file.Bytes == unrestrict.Filesize {
file.Link = unrestrict.Link
assigned = true
assignedCount++
}
})
if !assigned {
if strings.HasSuffix(unrestrict.Filename, ".rar") {
rarCount++
}
unassignedDownloads = append(unassignedDownloads, unrestrict)
} else {
assignedLinks = append(assignedLinks, unrestrict.Link)
}
return false
})
torrent.UnassignedLinks = torrent.UnassignedLinks.Difference(mapset.NewSet(assignedLinks...))
if assignedCount > 0 {
t.log.Infof("Assigned %d links to selected files for torrent %s", assignedCount, t.GetKey(torrent))
@@ -197,7 +201,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
Bytes: unassigned.Filesize,
Selected: 1,
},
Ended: torrent.LatestAdded,
Ended: torrent.Added,
Link: unassigned.Link,
}
torrent.SelectedFiles.Set(unassigned.Filename, newFile)
@@ -377,7 +381,7 @@ func (t *TorrentManager) markAsUnfixable(torrent *Torrent) {
torrent.DownloadedIDs.Each(func(id string) bool {
info, _ := infoCache.Get(id)
info.Unfixable = true
t.writeTorrentToFile(id, info, false)
t.writeTorrentToFile(id, info)
return false
})
}