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"> <form method="get" action="/logs/upload">
<input type="submit" value="Upload logs" /> <input type="submit" value="Upload logs" />
</form> </form>
<form method="post" action="/reboot/worker"> <form method="post" action="/reboot-worker">
<input type="submit" value="Reboot worker pool" /> <input type="submit" value="Reboot worker pool" />
</form> </form>
<form method="post" action="/reboot/refresh"> <form method="post" action="/reboot-refresh">
<input type="submit" value="Reboot refresh worker" /> <input type="submit" value="Reboot refresh worker" />
</form> </form>
<form method="post" action="/reboot/repair"> <form method="post" action="/reboot-repair">
<input type="submit" value="Reboot repair worker" /> <input type="submit" value="Reboot repair worker" />
</form> </form>
<form method="post" action="/remount/downloads"> <form method="post" action="/downloads/remount">
<input type="submit" value="Remount downloads" /> <input type="submit" value="Remount downloads" />
</form> </form>
<form method="post" action="/dump/torrents"> <form method="post" action="/torrents/dump">
<input type="submit" value="Dump torrents" /> <input type="submit" value="Dump torrents" />
</form> </form>
<form method="post" action="/torrents/analyze">
<input type="submit" value="Analyze torrents" />
</form>
</td> </td>
</tr> </tr>
</table> </table>
@@ -387,6 +390,13 @@ func (zr *Handlers) handleDumpTorrents(resp http.ResponseWriter, req *http.Reque
fmt.Fprint(resp, "Dumping torrents...") 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 { func bToMb(b uint64) uint64 {
return b / 1024 / 1024 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.Use(hs.options)
router.Get("/", hs.handleHome) router.Get("/", hs.handleHome)
router.Post("/reboot/worker", hs.handleRebootWorkerPool) router.Post("/reboot-worker", hs.handleRebootWorkerPool)
router.Post("/reboot/refresh", hs.handleRebootRefreshWorker) router.Post("/reboot-refresh", hs.handleRebootRefreshWorker)
router.Post("/reboot/repair", hs.handleRebootRepairWorker) router.Post("/reboot-repair", hs.handleRebootRepairWorker)
router.Post("/remount/downloads", hs.handleRemountDownloads) router.Post("/downloads/remount", hs.handleRemountDownloads)
router.Post("/dump/torrents", hs.handleDumpTorrents) router.Post("/torrents/dump", hs.handleDumpTorrents)
router.Post("/torrents/analyze", hs.handleAnalyzeTorrents)
// version // version
router.Get(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleVersionFile) router.Get(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleVersionFile)
router.Head(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleCheckVersionFile) router.Head(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleCheckVersionFile)

View File

@@ -42,6 +42,7 @@ type TorrentManager struct {
RepairKillSwitch chan struct{} RepairKillSwitch chan struct{}
RemountTrigger chan struct{} RemountTrigger chan struct{}
DumpTrigger chan struct{} DumpTrigger chan struct{}
AnalyzeTrigger chan struct{}
latestState *LibraryState latestState *LibraryState
@@ -102,18 +103,11 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
t.StartDownloadsJob() t.StartDownloadsJob()
t.StartRepairJob() t.StartRepairJob()
t.StartDumpJob() t.StartDumpJob()
t.StartMediaAnalysisJob()
t.setNewLatestState(t.getCurrentState()) t.setNewLatestState(t.getCurrentState())
t.TriggerRepair(nil) 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 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() { func (t *TorrentManager) initializeDirectoryMaps() {
// create internal directories // create internal directories
t.DirectoryMap.Set(INT_ALL, cmap.New[*Torrent]()) // key is GetAccessKey() t.DirectoryMap.Set(INT_ALL, cmap.New[*Torrent]()) // key is GetAccessKey()