administration

This commit is contained in:
2026-06-29 10:42:56 +02:00
parent e538e8b180
commit 1caad21d73
5 changed files with 235 additions and 31 deletions
+43 -11
View File
@@ -9,12 +9,15 @@
(require "private/flac-handling.rkt")
(require "private/opus-handling.rkt")
(require "private/log.rkt")
(require "private/store.rkt")
(require racket-audio)
(require simple-log)
(require simple-ini)
(provide audio-manager)
(store-config! #:kind 'keystore)
(define (audio-manager music-path opus-path #:log-level [log-level 'debug])
(let* ((ini-config-file (build-path music-path ".audio-manager.ini"))
(ini (file->ini ini-config-file))
@@ -23,10 +26,12 @@
(report-flac "")
(report-opus "")
(file-db-path (build-path music-path ".audio-manager.db"))
(file-db-hash (if (file-exists? file-db-path)
(deserialize (file->value file-db-path))
(make-hash)
))
(file-db-store (begin
(store-config! #:kind (ini-get ini
'manager
'storage-kind
'keystore))
(store-open file-db-path)))
(processed-dirs 0)
(processed-files 0)
(processed-opus 0)
@@ -39,6 +44,7 @@
(copied-files 0)
(failed-converts 0)
(failed-copies 0)
(not-in-source 0)
(processed-kind (make-hash))
(base-rate (ini-get ini 'flac 'max-khz 48000))
(dirs-logged -1)
@@ -161,8 +167,7 @@
(hash-set! info 'bits bits)
)
)
(values base-path path info)
)
(values base-path path info))
(define (flac-convert base-path path info)
(when (and (needs-processing? path info) (flac? path info))
@@ -238,7 +243,7 @@
(if (convert-to-opus path opus-file ini)
(begin
(set! converted-files (+ converted-files 1))
(info-am " Converted")
(info-am " Converted ~a" converted-files)
)
(begin
(info-am " CONVERSION PROBLEM")
@@ -281,13 +286,25 @@
path-part))))
(delete-directory/files rm-path #:must-exist? #f)
(let ((normalized-sub-path (hash-ref info 'path)))
(hash-remove! file-db-hash normalized-sub-path))
(store-remove! file-db-store normalized-sub-path))
)
)
)
)
(values base-path path info))
(define (updater base-path path info)
(when (not (eq? (hash-ref info 'file-db #f) 'deleted))
(let ((normalized-sub-path (hash-ref info 'path)))
(store-set! file-db-store normalized-sub-path info)))
(values base-path path info))
(define (target-tree-cleaner base-path path info)
(let ((normalized-sub-path (hash-ref info 'path)))
(unless (store-exists? file-db-store normalized-sub-path)
(set! not-in-source (+ not-in-source 1))))
(values base-path path info))
(define (log-processed-file base-path path info)
(dbg-am "processing ~a" path)
(if (eq? (hash-ref info 'type) 'dir)
@@ -358,6 +375,7 @@
(format "Copied files : ~a" copied-files)
(format "Failed convert : ~a" failed-converts)
(format "Failed copies : ~a" failed-copies)
(format "Not in source : ~a" not-in-source)
))
(subj (format "Audio manager report d.d. ~a" (date->yyyy-mm-dd (now))))
)
@@ -367,11 +385,12 @@
)
)
(sl-log-to-file&display (build-path music-path ".audio-manager.log"))
(info-am "Setting log level to ~a" log-level)
(sl-set-log-level log-level)
(let ((fw (make-file-admin music-path file-db-hash)))
(let ((fw (make-file-admin music-path file-db-store)))
;; Enrichment phase
(set! fw (fw-add-step fw adjust-ext))
(set! fw (fw-add-step fw flac-with-id3))
@@ -381,16 +400,29 @@
(set! fw (fw-add-step fw flac-picture))
(set! fw (fw-add-step fw to-opus))
(set! fw (fw-add-step fw copy-other))
;; Cleanup/Logging phase
;; Cleanup/Logging phase/updating
(set! fw (fw-add-step fw deleter))
(set! fw (fw-add-step fw log-processed-file))
(set! fw (fw-add-step fw updater))
(let loop ()
(let-values (((base-path path info) (fw)))
(if (eq? info #f)
(begin
(info-am "Finished walking music library")
(write-to-file (serialize file-db-hash) file-db-path #:exists 'replace)
;; Cleanup files in target, not in source
(info-am "Checking files in target, not in source")
(let ((fwt (make-file-walker opus-path "*" target-tree-cleaner)))
(let loop1 ()
(let-values (((base-path path info) (fwt)))
(if (eq? info #f)
(info-am "Target check finished")
(loop1)))))
(info-am "Closing store")
(store-close file-db-store)
(info-am "Reporting")
(report)
(info-am "Done")
'done)
(loop))))
)