Media analysis

This commit is contained in:
Ben Sarmiento
2024-05-26 04:21:22 +02:00
parent 4c23402c26
commit c203f11e76
3 changed files with 44 additions and 18 deletions

View File

@@ -42,6 +42,7 @@ type TorrentManager struct {
RepairKillSwitch chan struct{}
RemountTrigger chan struct{}
DumpTrigger chan struct{}
AnalyzeTrigger chan struct{}
latestState *LibraryState
@@ -102,18 +103,11 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
t.StartDownloadsJob()
t.StartRepairJob()
t.StartDumpJob()
t.StartMediaAnalysisJob()
t.setNewLatestState(t.getCurrentState())
t.TriggerRepair(nil)
t.log.Info("Applying media info details to all torrents")
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
allTorrents.IterCb(func(_ string, torrent *Torrent) {
t.applyMediaInfoDetails(torrent)
t.writeTorrentToFile(torrent)
t.log.Debugf("Applied media info details to torrent %s", t.GetKey(torrent))
})
})
return t
@@ -414,6 +408,27 @@ func (t *TorrentManager) StartDumpJob() {
})
}
func (t *TorrentManager) analyzeAllTorrents() {
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
totalCount := allTorrents.Count()
t.log.Infof("Applying media info details to all %d torrents", totalCount)
idx := 0
allTorrents.IterCb(func(_ string, torrent *Torrent) {
t.applyMediaInfoDetails(torrent)
t.writeTorrentToFile(torrent)
idx++
t.log.Debugf("Applied media info details to torrent %s (%d/%d)", t.GetKey(torrent), idx, totalCount)
})
}
func (t *TorrentManager) StartMediaAnalysisJob() {
_ = t.workerPool.Submit(func() {
for range t.AnalyzeTrigger {
t.analyzeAllTorrents()
}
})
}
func (t *TorrentManager) initializeDirectoryMaps() {
// create internal directories
t.DirectoryMap.Set(INT_ALL, cmap.New[*Torrent]()) // key is GetAccessKey()