Small fixes
This commit is contained in:
@@ -493,68 +493,6 @@ func (t *TorrentManager) deleteTorrentFile(torrentID string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([]*File, bool) {
|
||||
type Result struct {
|
||||
Response *realdebrid.Download
|
||||
}
|
||||
|
||||
resultsChan := make(chan Result, len(links))
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for _, link := range links {
|
||||
wg.Add(1)
|
||||
link := link // redeclare to avoid closure on loop variable
|
||||
// Use the existing worker pool to submit tasks
|
||||
_ = t.workerPool.Submit(func() {
|
||||
defer wg.Done()
|
||||
if t.DownloadCache.Has(link) {
|
||||
download, _ := t.DownloadCache.Get(link)
|
||||
resultsChan <- Result{Response: download}
|
||||
return
|
||||
}
|
||||
resp := t.UnrestrictUntilOk(link)
|
||||
resultsChan <- Result{Response: resp}
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
close(resultsChan)
|
||||
|
||||
chaoticFileCount := 0
|
||||
for result := range resultsChan {
|
||||
if result.Response == nil {
|
||||
continue
|
||||
}
|
||||
found := false
|
||||
for _, file := range selectedFiles {
|
||||
if strings.Contains(file.Path, result.Response.Filename) {
|
||||
file.Link = result.Response.Link
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
if result.Response.Streamable == 1 {
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
selectedFiles = append(selectedFiles, &File{
|
||||
File: realdebrid.File{
|
||||
ID: math.MaxInt32,
|
||||
Path: result.Response.Filename,
|
||||
Bytes: result.Response.Filesize,
|
||||
Selected: 1,
|
||||
},
|
||||
Added: now,
|
||||
Ended: now,
|
||||
Link: result.Response.Link,
|
||||
})
|
||||
} else {
|
||||
chaoticFileCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return selectedFiles, chaoticFileCount == len(links)
|
||||
}
|
||||
|
||||
func (t *TorrentManager) repairAll() {
|
||||
proceed := t.canCapacityHandle() // blocks for approx 45 minutes if active torrents are full
|
||||
if !proceed {
|
||||
|
||||
Reference in New Issue
Block a user