saveTorrentChangesToDisk when relevant
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/debridmediamanager/zurg/pkg/utils"
|
"github.com/debridmediamanager/zurg/pkg/utils"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MainApp(configPath string) {
|
func MainApp(configPath string) {
|
||||||
@@ -28,6 +29,10 @@ func MainApp(configPath string) {
|
|||||||
log := logutil.NewLogger(logPath)
|
log := logutil.NewLogger(logPath)
|
||||||
zurglog := log.Named("zurg")
|
zurglog := log.Named("zurg")
|
||||||
|
|
||||||
|
if log.Level() == zapcore.DebugLevel {
|
||||||
|
zurglog.Infof("debug logging is enabled; if you are not debugging please set LOG_LEVEL=info in your environment")
|
||||||
|
}
|
||||||
|
|
||||||
zurglog.Debugf("PID: %d", os.Getpid())
|
zurglog.Debugf("PID: %d", os.Getpid())
|
||||||
zurglog.Infof("Version: %s", version.GetVersion())
|
zurglog.Infof("Version: %s", version.GetVersion())
|
||||||
zurglog.Infof("GitCommit: %s", version.GetGitCommit())
|
zurglog.Infof("GitCommit: %s", version.GetGitCommit())
|
||||||
|
|||||||
@@ -246,9 +246,6 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torren
|
|||||||
fileNames[i] = ""
|
fileNames[i] = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.Contains(torrentName, "Hellraiser") {
|
|
||||||
fmt.Printf("+%v\n", fileNames)
|
|
||||||
}
|
|
||||||
return checkArithmeticSequenceInFilenames(fileNames)
|
return checkArithmeticSequenceInFilenames(fileNames)
|
||||||
}
|
}
|
||||||
if filter.FileInsideSizeGreaterThanOrEqual > 0 {
|
if filter.FileInsideSizeGreaterThanOrEqual > 0 {
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
|||||||
if len(unselectedIDs) == torrent.SelectedFiles.Count() && len(unselectedIDs) > 0 {
|
if len(unselectedIDs) == torrent.SelectedFiles.Count() && len(unselectedIDs) > 0 {
|
||||||
return true
|
return true
|
||||||
} else if len(unselectedIDs) > 0 {
|
} else if len(unselectedIDs) > 0 {
|
||||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
|
||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
|
||||||
info, _ := infoCache.Get(id)
|
|
||||||
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
for _, unselectedID := range unselectedIDs {
|
for _, unselectedID := range unselectedIDs {
|
||||||
if file.ID == unselectedID {
|
if file.ID == unselectedID {
|
||||||
@@ -23,8 +21,6 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.writeTorrentToFile(id, info)
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -201,3 +201,18 @@ func (t *TorrentManager) initializeDirectories() {
|
|||||||
t.DirectoryMap.Set(directory, cmap.New[*Torrent]())
|
t.DirectoryMap.Set(directory, cmap.New[*Torrent]())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TorrentManager) saveTorrentChangesToDisk(torrent *Torrent, cb func(*Torrent)) {
|
||||||
|
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||||
|
torrent.DownloadedIDs.Union(torrent.InProgressIDs).Each(func(id string) bool {
|
||||||
|
info, exists := infoCache.Get(id)
|
||||||
|
if !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if cb != nil {
|
||||||
|
cb(info)
|
||||||
|
}
|
||||||
|
t.writeTorrentToFile(id, info)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
torrent.BrokenLinks = mapset.NewSet[string]()
|
torrent.BrokenLinks = mapset.NewSet[string]()
|
||||||
|
|
||||||
infoCache.Set(rdTorrent.ID, &torrent)
|
infoCache.Set(rdTorrent.ID, &torrent)
|
||||||
t.writeTorrentToFile(rdTorrent.ID, &torrent)
|
t.saveTorrentChangesToDisk(&torrent, nil)
|
||||||
|
|
||||||
return &torrent
|
return &torrent
|
||||||
}
|
}
|
||||||
@@ -290,18 +290,6 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// broken links
|
|
||||||
if mainTorrent.BrokenLinks.Cardinality() > 0 {
|
|
||||||
mainTorrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
|
||||||
mainTorrent.BrokenLinks.Each(func(brokenLink string) bool {
|
|
||||||
if file.Link == brokenLink {
|
|
||||||
file.Link = ""
|
|
||||||
}
|
|
||||||
return file.Link == brokenLink
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if existing.Added < toMerge.Added {
|
if existing.Added < toMerge.Added {
|
||||||
mainTorrent.Added = toMerge.Added
|
mainTorrent.Added = toMerge.Added
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -92,9 +92,7 @@ func (t *TorrentManager) repairAll(torrent *Torrent) {
|
|||||||
// save the broken files to the file cache
|
// save the broken files to the file cache
|
||||||
// broken files are also added when trying to open a file
|
// broken files are also added when trying to open a file
|
||||||
if torrent.BrokenLinks.Cardinality() > 0 {
|
if torrent.BrokenLinks.Cardinality() > 0 {
|
||||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
|
||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
|
||||||
info, _ := infoCache.Get(id)
|
|
||||||
hasBrokenFiles := false
|
hasBrokenFiles := false
|
||||||
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
torrent.BrokenLinks.Each(func(brokenLink string) bool {
|
torrent.BrokenLinks.Each(func(brokenLink string) bool {
|
||||||
@@ -108,9 +106,7 @@ func (t *TorrentManager) repairAll(torrent *Torrent) {
|
|||||||
})
|
})
|
||||||
if hasBrokenFiles {
|
if hasBrokenFiles {
|
||||||
info.BrokenLinks = torrent.BrokenLinks
|
info.BrokenLinks = torrent.BrokenLinks
|
||||||
t.writeTorrentToFile(id, info)
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +179,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
|
|
||||||
// handle torrents with incomplete links for selected files
|
// handle torrents with incomplete links for selected files
|
||||||
if !t.assignUnassignedLinks(torrent) {
|
if !t.assignUnassignedLinks(torrent) {
|
||||||
|
t.log.Debugf("Ending repair process early for torrent %s", t.GetKey(torrent))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +203,9 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
ix++
|
ix++
|
||||||
})
|
})
|
||||||
torrent.BrokenLinks = mapset.NewSet[string]()
|
torrent.BrokenLinks = mapset.NewSet[string]()
|
||||||
|
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
|
||||||
|
info.BrokenLinks = mapset.NewSet[string]()
|
||||||
|
})
|
||||||
t.log.Infof("Successfully repaired torrent %s using repair_method#1", t.GetKey(torrent))
|
t.log.Infof("Successfully repaired torrent %s using repair_method#1", t.GetKey(torrent))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -294,17 +294,12 @@ func (t *TorrentManager) assignUnassignedLinks(torrent *Torrent) bool {
|
|||||||
t.markAsUnfixable(torrent, "rar'ed by RD")
|
t.markAsUnfixable(torrent, "rar'ed by RD")
|
||||||
t.markAsUnplayable(torrent, "rar'ed by RD")
|
t.markAsUnplayable(torrent, "rar'ed by RD")
|
||||||
}
|
}
|
||||||
t.log.Debugf("Ending repair process early for torrent %s", t.GetKey(torrent))
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// empty the unassigned links as we have assigned them
|
// empty the unassigned links as we have assigned them
|
||||||
if torrent.UnassignedLinks.Cardinality() > 0 {
|
if torrent.UnassignedLinks.Cardinality() > 0 {
|
||||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
|
||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
|
||||||
info, _ := infoCache.Get(id)
|
|
||||||
info.UnassignedLinks = mapset.NewSet[string]()
|
info.UnassignedLinks = mapset.NewSet[string]()
|
||||||
t.writeTorrentToFile(id, info)
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,12 +464,8 @@ func (t *TorrentManager) markAsUnplayable(torrent *Torrent, reason string) {
|
|||||||
func (t *TorrentManager) markAsUnfixable(torrent *Torrent, reason string) {
|
func (t *TorrentManager) markAsUnfixable(torrent *Torrent, reason string) {
|
||||||
t.log.Warnf("Marking torrent %s as unfixable - %s", t.GetKey(torrent), reason)
|
t.log.Warnf("Marking torrent %s as unfixable - %s", t.GetKey(torrent), reason)
|
||||||
torrent.UnrepairableReason = reason
|
torrent.UnrepairableReason = reason
|
||||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
t.saveTorrentChangesToDisk(torrent, func(t *Torrent) {
|
||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
t.UnrepairableReason = reason
|
||||||
info, _ := infoCache.Get(id)
|
|
||||||
info.UnrepairableReason = reason
|
|
||||||
t.writeTorrentToFile(id, info)
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,6 +553,9 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
torrent.BrokenLinks = mapset.NewSet[string]()
|
torrent.BrokenLinks = mapset.NewSet[string]()
|
||||||
|
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
|
||||||
|
info.BrokenLinks = mapset.NewSet[string]()
|
||||||
|
})
|
||||||
t.log.Infof("Successfully repaired torrent %s using repair_method#2", t.GetKey(torrent))
|
t.log.Infof("Successfully repaired torrent %s using repair_method#2", t.GetKey(torrent))
|
||||||
} else {
|
} else {
|
||||||
t.log.Warnf("repair_method#2: Fixer is done but torrent %s is still broken; let's keep the fixer", t.GetKey(torrent))
|
t.log.Warnf("repair_method#2: Fixer is done but torrent %s is still broken; let's keep the fixer", t.GetKey(torrent))
|
||||||
|
|||||||
Reference in New Issue
Block a user