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

@@ -269,21 +269,24 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
<form method="get" action="/logs/upload">
<input type="submit" value="Upload logs" />
</form>
<form method="post" action="/reboot/worker">
<form method="post" action="/reboot-worker">
<input type="submit" value="Reboot worker pool" />
</form>
<form method="post" action="/reboot/refresh">
<form method="post" action="/reboot-refresh">
<input type="submit" value="Reboot refresh worker" />
</form>
<form method="post" action="/reboot/repair">
<form method="post" action="/reboot-repair">
<input type="submit" value="Reboot repair worker" />
</form>
<form method="post" action="/remount/downloads">
<form method="post" action="/downloads/remount">
<input type="submit" value="Remount downloads" />
</form>
<form method="post" action="/dump/torrents">
<form method="post" action="/torrents/dump">
<input type="submit" value="Dump torrents" />
</form>
<form method="post" action="/torrents/analyze">
<input type="submit" value="Analyze torrents" />
</form>
</td>
</tr>
</table>
@@ -387,6 +390,13 @@ func (zr *Handlers) handleDumpTorrents(resp http.ResponseWriter, req *http.Reque
fmt.Fprint(resp, "Dumping torrents...")
}
func (zr *Handlers) handleAnalyzeTorrents(resp http.ResponseWriter, req *http.Request) {
resp.Header().Set("Refresh", "2; url=/")
zr.torMgr.AnalyzeTrigger <- struct{}{}
zr.log.Infof("Triggered media analysis of torrents")
fmt.Fprint(resp, "Analyzing all torrents...")
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}

View File

@@ -50,11 +50,12 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
router.Use(hs.options)
router.Get("/", hs.handleHome)
router.Post("/reboot/worker", hs.handleRebootWorkerPool)
router.Post("/reboot/refresh", hs.handleRebootRefreshWorker)
router.Post("/reboot/repair", hs.handleRebootRepairWorker)
router.Post("/remount/downloads", hs.handleRemountDownloads)
router.Post("/dump/torrents", hs.handleDumpTorrents)
router.Post("/reboot-worker", hs.handleRebootWorkerPool)
router.Post("/reboot-refresh", hs.handleRebootRefreshWorker)
router.Post("/reboot-repair", hs.handleRebootRepairWorker)
router.Post("/downloads/remount", hs.handleRemountDownloads)
router.Post("/torrents/dump", hs.handleDumpTorrents)
router.Post("/torrents/analyze", hs.handleAnalyzeTorrents)
// version
router.Get(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleVersionFile)
router.Head(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleCheckVersionFile)

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()