Automatic media analysis for new items

This commit is contained in:
Ben Adrian Sarmiento
2024-06-19 00:02:04 +02:00
parent acc9b69b5a
commit 74052e2f67
3 changed files with 25 additions and 8 deletions

View File

@@ -127,10 +127,18 @@ func MainApp(configPath string) {
zurglog, zurglog,
) )
hasFFprobe := true
_, err = exec.LookPath("ffprobe")
if err != nil {
hasFFprobe = false
zurglog.Warn("ffprobe not found in PATH (do you have ffmpeg installed?), you won't be able to perform media analysis")
}
torrentMgr := torrent.NewTorrentManager( torrentMgr := torrent.NewTorrentManager(
config, config,
api, api,
workerPool, workerPool,
hasFFprobe,
log.Named("manager"), log.Named("manager"),
log.Named("repair"), log.Named("repair"),
) )
@@ -148,11 +156,6 @@ func MainApp(configPath string) {
log.Named("router"), log.Named("router"),
) )
_, err = exec.LookPath("ffprobe")
if err != nil {
zurglog.Warn("ffprobe not found in PATH (do you have ffmpeg installed?), you won't be able to perform media analysis")
}
//// pprof //// pprof
// workerPool.Submit(func() { // workerPool.Submit(func() {
// if err := netHttp.ListenAndServe(":6060", nil); err != nil && err != netHttp.ErrServerClosed { // if err := netHttp.ListenAndServe(":6060", nil); err != nil && err != netHttp.ErrServerClosed {

View File

@@ -55,12 +55,13 @@ type TorrentManager struct {
OnceDoneBin mapset.Set[string] OnceDoneBin mapset.Set[string]
DeleteOnCompletionBin cmap.ConcurrentMap[string, string] DeleteOnCompletionBin cmap.ConcurrentMap[string, string]
hasFFprobe bool
} }
// NewTorrentManager creates a new torrent manager // NewTorrentManager creates a new torrent manager
// it will fetch all torrents and their info in the background // it will fetch all torrents and their info in the background
// and store them in-memory and cached in files // and store them in-memory and cached in files
func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, workerPool *ants.Pool, log, repairLog *logutil.Logger) *TorrentManager { func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, workerPool *ants.Pool, hasFFprobe bool, log, repairLog *logutil.Logger) *TorrentManager {
t := &TorrentManager{ t := &TorrentManager{
requiredVersion: "0.10.0", requiredVersion: "0.10.0",
@@ -87,6 +88,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
OnceDoneBin: mapset.NewSet[string](), OnceDoneBin: mapset.NewSet[string](),
DeleteOnCompletionBin: cmap.New[string](), DeleteOnCompletionBin: cmap.New[string](),
hasFFprobe: hasFFprobe,
} }
t.initializeBins() t.initializeBins()

View File

@@ -27,6 +27,7 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
var mergeChan = make(chan *Torrent, len(instances)) var mergeChan = make(chan *Torrent, len(instances))
allTorrents, _ := t.DirectoryMap.Get(INT_ALL) allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
oldKeys := mapset.NewSet[string](allTorrents.Keys()...)
freshIDs := mapset.NewSet[string]() freshIDs := mapset.NewSet[string]()
freshAccessKeys := mapset.NewSet[string]() freshAccessKeys := mapset.NewSet[string]()
@@ -87,9 +88,20 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
t.assignDirectory(mainTorrent, !initialRun) t.assignDirectory(mainTorrent, !initialRun)
} }
// new torrents
t.workerPool.Submit(func() {
if !t.hasFFprobe {
return
}
freshAccessKeys.Difference(oldKeys).Each(func(accessKey string) bool {
torrent, _ := allTorrents.Get(accessKey)
t.applyMediaInfoDetails(torrent)
return false
})
})
// removed torrents // removed torrents
oldPlusNewKeys := mapset.NewSet[string](allTorrents.Keys()...) oldKeys.Difference(freshAccessKeys).Each(func(accessKey string) bool {
oldPlusNewKeys.Difference(freshAccessKeys).Each(func(accessKey string) bool {
t.Delete(accessKey, false) t.Delete(accessKey, false)
return false return false
}) })