Fix link reassignment
This commit is contained in:
@@ -182,10 +182,11 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
t.log.Infof("repair_method#1: Torrent %s is still in progress but it should work once done (torrent is temporarily hidden until download has completed)", t.GetKey(torrent))
|
t.log.Infof("repair_method#1: Torrent %s is still in progress but it should work once done (torrent is temporarily hidden until download has completed)", t.GetKey(torrent))
|
||||||
return
|
return
|
||||||
} else if info != nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) {
|
} else if info != nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) {
|
||||||
|
selectedFiles := getSelectedFiles(info)
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, oldFile *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, oldFile *File) {
|
||||||
for ix, newFile := range info.Files {
|
for _, newFile := range selectedFiles {
|
||||||
if oldFile.Bytes == newFile.Bytes {
|
if oldFile.Bytes == newFile.Bytes {
|
||||||
oldFile.Link = info.Links[ix]
|
oldFile.Link = newFile.Link
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -527,10 +528,11 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent {
|
|||||||
|
|
||||||
if info.IsDone() {
|
if info.IsDone() {
|
||||||
if !t.isStillBroken(info, brokenFiles) {
|
if !t.isStillBroken(info, brokenFiles) {
|
||||||
|
selectedFiles := getSelectedFiles(info)
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, oldFile *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, oldFile *File) {
|
||||||
for ix, newFile := range info.Files {
|
for _, newFile := range selectedFiles {
|
||||||
if oldFile.Bytes == newFile.Bytes {
|
if oldFile.Bytes == newFile.Bytes {
|
||||||
oldFile.Link = info.Links[ix]
|
oldFile.Link = newFile.Link
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -551,3 +553,25 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent {
|
|||||||
t.deleteOnceDone.Add(fixer.ID)
|
t.deleteOnceDone.Add(fixer.ID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getSelectedFiles(info *realdebrid.TorrentInfo) []*File {
|
||||||
|
var selectedFiles []*File
|
||||||
|
// if some Links are empty, we need to repair it
|
||||||
|
for _, file := range info.Files {
|
||||||
|
if file.Selected == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
selectedFiles = append(selectedFiles, &File{
|
||||||
|
File: file,
|
||||||
|
Ended: info.Ended,
|
||||||
|
Link: "", // no link yet
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(selectedFiles) == len(info.Links) {
|
||||||
|
// all links are still intact! good!
|
||||||
|
for i, file := range selectedFiles {
|
||||||
|
file.Link = info.Links[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectedFiles
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user