Adjust logging for unplayable dir and assigning directories

This commit is contained in:
Ben Adrian Sarmiento
2024-07-05 16:47:36 +02:00
parent dacf2983a6
commit b501b800dd
3 changed files with 17 additions and 7 deletions

View File

@@ -103,14 +103,14 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
t.workerPool.Submit(func() { t.workerPool.Submit(func() {
defer wg.Done() defer wg.Done()
// load *.zurgtorrent files // initial load of existing *.zurgtorrent files
allTorrents, _ := t.DirectoryMap.Get(INT_ALL) allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
t.getTorrentFiles("data").Each(func(filePath string) bool { t.getTorrentFiles("data").Each(func(filePath string) bool {
torrent := t.readTorrentFromFile(filePath) torrent := t.readTorrentFromFile(filePath)
if torrent != nil { if torrent != nil {
accessKey := t.GetKey(torrent) accessKey := t.GetKey(torrent)
allTorrents.Set(accessKey, torrent) allTorrents.Set(accessKey, torrent)
t.assignDirectory(torrent, false) t.assignDirectory(torrent, false, false)
} }
return false return false
}) })

View File

@@ -62,7 +62,7 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
if !exists { if !exists {
allTorrents.Set(accessKey, torrent) allTorrents.Set(accessKey, torrent)
t.writeTorrentToFile(torrent) t.writeTorrentToFile(torrent)
t.assignDirectory(torrent, !initialRun) t.assignDirectory(torrent, !initialRun, true)
} else if !mainTorrent.DownloadedIDs.ContainsOne(tInfo.ID) { } else if !mainTorrent.DownloadedIDs.ContainsOne(tInfo.ID) {
forMerging = torrent forMerging = torrent
} }
@@ -93,7 +93,7 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
mainTorrent := t.mergeTorrents(existing, torrent) mainTorrent := t.mergeTorrents(existing, torrent)
allTorrents.Set(accessKey, mainTorrent) allTorrents.Set(accessKey, mainTorrent)
t.writeTorrentToFile(mainTorrent) t.writeTorrentToFile(mainTorrent)
t.assignDirectory(mainTorrent, !initialRun) t.assignDirectory(mainTorrent, !initialRun, true)
} }
// new torrents // new torrents
@@ -344,7 +344,7 @@ func (t *TorrentManager) mergeTorrents(existing, toMerge *Torrent) *Torrent {
return mergedTorrent return mergedTorrent
} }
func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) { func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool, outputLogs bool) {
accessKey := t.GetKey(tor) accessKey := t.GetKey(tor)
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) { t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
@@ -372,6 +372,9 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) {
}) })
if unplayable { if unplayable {
if outputLogs {
t.log.Warnf("No playable files for %s, moving to unplayable directory", accessKey)
}
t.markAsUnplayable(tor, "no playable files") t.markAsUnplayable(tor, "no playable files")
return return
} }
@@ -380,6 +383,7 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) {
switch t.Config.GetVersion() { switch t.Config.GetVersion() {
case "v1": case "v1":
updatedPaths := make([]string, 0) updatedPaths := make([]string, 0)
dirs := make([]string, 0)
configV1 := t.Config.(*config.ZurgConfigV1) configV1 := t.Config.(*config.ZurgConfigV1)
for _, directories := range configV1.GetGroupMap() { for _, directories := range configV1.GetGroupMap() {
for _, directory := range directories { for _, directory := range directories {
@@ -387,6 +391,10 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) {
listing, _ := t.DirectoryMap.Get(directory) listing, _ := t.DirectoryMap.Get(directory)
listing.Set(accessKey, tor) listing.Set(accessKey, tor)
if directory != INT_ALL {
dirs = append(dirs, directory)
}
if triggerHook { if triggerHook {
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey)) updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey))
} }
@@ -397,6 +405,9 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) {
if triggerHook { if triggerHook {
OnLibraryUpdateHook(updatedPaths, t.Config, t.log) OnLibraryUpdateHook(updatedPaths, t.Config, t.log)
} }
if outputLogs {
t.log.Infof("Assigned %s to: %s", accessKey, strings.Join(dirs, ", "))
}
} }
} }

View File

@@ -445,7 +445,7 @@ func (t *TorrentManager) assignLinks(torrent *Torrent) bool {
} }
} }
} else { } else {
t.repairLog.Warnf("Torrent %s is rar'ed and we cannot repair it", t.GetKey(torrent)) t.repairLog.Warnf("Torrent %s is rar'ed and we cannot repair it, moving to unplayable directory", t.GetKey(torrent))
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")
torrent.State.Event(context.Background(), "mark_as_repaired") torrent.State.Event(context.Background(), "mark_as_repaired")
@@ -604,7 +604,6 @@ func (t *TorrentManager) canCapacityHandle() bool {
} }
func (t *TorrentManager) markAsUnplayable(torrent *Torrent, reason string) { func (t *TorrentManager) markAsUnplayable(torrent *Torrent, reason string) {
t.repairLog.Debugf("Torrent %s is unplayable (reason: %s), moving to unplayable directory", t.GetKey(torrent), reason)
// reassign to unplayable torrents directory // reassign to unplayable torrents directory
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) { t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
if strings.HasPrefix(directory, "int__") { if strings.HasPrefix(directory, "int__") {