Refinements

This commit is contained in:
Ben Sarmiento
2023-10-19 23:00:35 +02:00
parent fda45b99ff
commit a65019e202
7 changed files with 149 additions and 126 deletions

View File

@@ -94,6 +94,7 @@ func (t *TorrentManager) getAll() []Torrent {
var torrentsV2 []Torrent
for _, torrent := range torrents {
torrent.Name = strings.TrimSuffix(torrent.Name, "/")
torrentV2 := Torrent{
Torrent: torrent,
SelectedFiles: nil,
@@ -184,11 +185,10 @@ func (t *TorrentManager) getInfo(torrentID string) *Torrent {
}
if len(selectedFiles) != len(info.Links) {
// TODO: This means some files have expired
// we need to re-add the torrent
// we need to 'fix' this torrent then, at least the missing selected files
log.Println("Some links has expired for", info.Name)
type Result struct {
Filename string
Link string
Response *realdebrid.UnrestrictResponse
}
resultsChan := make(chan Result, len(info.Links))
@@ -209,7 +209,7 @@ func (t *TorrentManager) getInfo(torrentID string) *Torrent {
}
resp := realdebrid.RetryUntilOk(unrestrictFn)
if resp != nil {
resultsChan <- Result{Filename: resp.Filename, Link: resp.Link}
resultsChan <- Result{Response: resp}
}
}(link)
}
@@ -221,11 +221,23 @@ func (t *TorrentManager) getInfo(torrentID string) *Torrent {
}()
for result := range resultsChan {
found := false
for i := range selectedFiles {
if strings.HasSuffix(selectedFiles[i].Path, result.Filename) {
selectedFiles[i].Link = result.Link
if strings.HasSuffix(selectedFiles[i].Path, result.Response.Filename) {
selectedFiles[i].Link = result.Response.Link
found = true
}
}
if !found {
selectedFiles = append(selectedFiles, File{
File: realdebrid.File{
Path: result.Response.Filename,
Bytes: result.Response.Filesize,
Selected: 1,
},
Link: result.Response.Link,
})
}
}
} else {
for i, link := range info.Links {