Simple repair

This commit is contained in:
Ben Sarmiento
2023-12-03 02:58:43 +01:00
parent 286628cdc6
commit 3c9d4079f5

View File

@@ -15,7 +15,6 @@ import (
"github.com/debridmediamanager/zurg/internal/config"
"github.com/debridmediamanager/zurg/pkg/dav"
"github.com/debridmediamanager/zurg/pkg/realdebrid"
"github.com/debridmediamanager/zurg/pkg/utils"
"github.com/dgraph-io/ristretto"
cmap "github.com/orcaman/concurrent-map/v2"
"github.com/panjf2000/ants/v2"
@@ -643,50 +642,6 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return
}
// make the file messy
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 utils.IsStreamable(file.Path) {
streamableCount++
}
fileCopy := &File{
File: file.File,
Added: file.Added,
Ended: file.Ended,
Link: file.Link,
}
selectedFiles = append(selectedFiles, fileCopy)
if strings.HasPrefix(fileCopy.Link, "http") {
links = append(links, fileCopy.Link)
}
fileCopy.Link = "" // empty the links = chaos!
})
// 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
selectedFiles, isChaotic = t.organizeChaos(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.Delete(torrent.AccessKey, false, true)
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.Delete(torrent.AccessKey, false, true)
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
} else {
torrent.SelectedFiles.Set(filepath.Base(newFile.Path), newFile)
}
}
proceed := t.canCapacityHandle() // blocks for approx 45 minutes if active torrents are full
if !proceed {
t.log.Error("Reached the max number of active torrents, cannot continue with the repair")
@@ -710,7 +665,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
// if we download a single file, it will be named differently
// so we need to download 1 extra file to preserve the name
// this is only relevant if we enable retain_rd_torrent_name
if len(missingFiles) == 1 && streamableCount > 1 {
if len(missingFiles) == 1 && torrent.SelectedFiles.Count() > 1 {
// add the first file link encountered with a prefix of http
for _, file := range torrent.SelectedFiles.Items() {
if strings.HasPrefix(file.Link, "http") {