Separated the eager repair work done on getting info
This commit is contained in:
@@ -359,12 +359,8 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
// if it is empty, it means the file is no longer available
|
||||
// Files+Links together are the same as SelectedFiles
|
||||
var selectedFiles []*File
|
||||
streamableCount := 0
|
||||
// if some Links are empty, we need to repair it
|
||||
for _, file := range info.Files {
|
||||
if isStreamable(file.Path) {
|
||||
streamableCount++
|
||||
}
|
||||
if file.Selected == 0 {
|
||||
continue
|
||||
}
|
||||
@@ -376,19 +372,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
})
|
||||
}
|
||||
if len(selectedFiles) > len(info.Links) && info.Progress == 100 {
|
||||
// chaotic file means RD will not output the desired file selection
|
||||
// e.g. even if we select just a single mkv, it will output a rar
|
||||
var isChaotic bool
|
||||
selectedFiles, isChaotic = t.organizeChaos(info.Links, selectedFiles)
|
||||
if isChaotic {
|
||||
t.log.Warnf("Torrent id=%s %s is unplayable; it is always returning a rar file (it will no longer show up in your directories, zurg suggests you delete it)", info.ID, info.Name)
|
||||
// t.log.Debugf("You can try fixing it yourself magnet:?xt=urn:btih:%s", info.Hash)
|
||||
return nil
|
||||
} else if streamableCount == 1 {
|
||||
t.log.Warnf("Torrent id=%s %s is unplayable; the lone streamable link has expired (it will no longer show up in your directories, zurg suggests you delete it)", info.ID, info.Name)
|
||||
// t.log.Debugf("You can try fixing it yourself magnet:?xt=urn:btih:%s", info.Hash)
|
||||
return nil
|
||||
}
|
||||
t.log.Warnf("Torrent id=%s is partly expired, it has %d selected files but only %d links", info.ID, len(selectedFiles), len(info.Links))
|
||||
} else if len(selectedFiles) == len(info.Links) {
|
||||
// all links are still intact! good!
|
||||
for i, file := range selectedFiles {
|
||||
@@ -482,14 +466,14 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([
|
||||
for _, link := range links {
|
||||
wg.Add(1)
|
||||
link := link // redeclare to avoid closure on loop variable
|
||||
// Use the existing workerPool to submit tasks
|
||||
// Use the existing worker pool to submit tasks
|
||||
err := t.antsPool.Submit(func() {
|
||||
defer wg.Done()
|
||||
resp := t.api.UnrestrictUntilOk(link)
|
||||
resultsChan <- Result{Response: resp}
|
||||
})
|
||||
if err != nil {
|
||||
t.log.Errorf("Error submitting task to workerPool: %v", err)
|
||||
t.log.Errorf("Error submitting task to worker pool: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,8 +565,13 @@ func (t *TorrentManager) Repair(accessKey string) {
|
||||
t.log.Infof("Evaluating whole torrent to find the correct files for torrent: %s", torrent.AccessKey)
|
||||
|
||||
var selectedFiles []*File
|
||||
var isChaotic bool
|
||||
var links []string
|
||||
streamableCount := 0
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
if isStreamable(file.Path) {
|
||||
streamableCount++
|
||||
}
|
||||
fileCopy := &File{
|
||||
File: file.File,
|
||||
Added: file.Added,
|
||||
@@ -595,7 +584,27 @@ func (t *TorrentManager) Repair(accessKey string) {
|
||||
}
|
||||
fileCopy.Link = "" // empty the links = chaos!
|
||||
})
|
||||
selectedFiles, _ = t.organizeChaos(links, selectedFiles)
|
||||
selectedFiles, isChaotic = t.organizeChaos(links, selectedFiles)
|
||||
// chaotic file means RD will not output the desired file selection
|
||||
// // e.g. even if we select just a single mkv, it will output a rar
|
||||
// var isChaotic bool
|
||||
// selectedFiles, isChaotic = t.organizeChaos(info.Links, selectedFiles)
|
||||
if isChaotic {
|
||||
t.log.Warnf("Torrent %s is always returning an unplayable rar file (it will no longer show up in your directories, zurg suggests you delete it)", torrent.AccessKey)
|
||||
t.DirectoryMap.IterCb(func(_ string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
||||
torrents.Remove(torrent.AccessKey)
|
||||
})
|
||||
// t.log.Debugf("You can try fixing it yourself magnet:?xt=urn:btih:%s", info.Hash)
|
||||
return
|
||||
} else if streamableCount == 1 {
|
||||
t.log.Warnf("Torrent %s only file has expired (it will no longer show up in your directories, zurg suggests you delete it)", torrent.AccessKey)
|
||||
t.log.Debugf("You can try fixing it yourself magnet:?xt=urn:btih:%s", torrent.Instances[0].Hash)
|
||||
t.DirectoryMap.IterCb(func(_ string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
||||
torrents.Remove(torrent.AccessKey)
|
||||
})
|
||||
return
|
||||
}
|
||||
// t.log.Debugf("Identified the expired files of torrent id=%s", info.ID)
|
||||
for _, newFile := range selectedFiles {
|
||||
if file, exists := torrent.SelectedFiles.Get(filepath.Base(newFile.Path)); exists {
|
||||
file.Link = newFile.Link
|
||||
|
||||
Reference in New Issue
Block a user