string keys are stored as strings.
This commit is contained in:
+96
-33
@@ -1,18 +1,19 @@
|
||||
#lang racket/base
|
||||
|
||||
(require racket/file)
|
||||
(require racket/serialize)
|
||||
(require racket/string)
|
||||
(require "private/file-walker.rkt")
|
||||
(require "private/util.rkt")
|
||||
(require "private/mail.rkt")
|
||||
(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)
|
||||
(require racket/file
|
||||
racket/serialize
|
||||
racket/port
|
||||
racket/string
|
||||
"private/file-walker.rkt"
|
||||
"private/util.rkt"
|
||||
"private/mail.rkt"
|
||||
"private/flac-handling.rkt"
|
||||
"private/opus-handling.rkt"
|
||||
"private/log.rkt"
|
||||
"private/store.rkt"
|
||||
racket-audio
|
||||
simple-log
|
||||
simple-ini)
|
||||
|
||||
(provide audio-manager)
|
||||
|
||||
@@ -44,7 +45,13 @@
|
||||
(copied-files 0)
|
||||
(failed-converts 0)
|
||||
(failed-copies 0)
|
||||
(files-in-target 0)
|
||||
(dirs-in-target 0)
|
||||
(last-dirs-in-target -1)
|
||||
(not-in-source 0)
|
||||
(jobs 0)
|
||||
(max-jobs (ini-get ini 'audio-manager 'max-jobs 6))
|
||||
(job-nr 0)
|
||||
(processed-kind (make-hash))
|
||||
(base-rate (ini-get ini 'flac 'max-khz 48000))
|
||||
(dirs-logged -1)
|
||||
@@ -113,6 +120,10 @@
|
||||
(eq? s 'flac))
|
||||
#f))
|
||||
|
||||
(define (opus? info)
|
||||
(and (eq? (hash-ref info 'type) 'file)
|
||||
(eq? (hash-ref info 'ext) 'opus)))
|
||||
|
||||
(define (rep-id3 path)
|
||||
(set! report-flacs-with-id3
|
||||
(string-append report-flacs-with-id3
|
||||
@@ -222,6 +233,7 @@
|
||||
)
|
||||
(values base-path path info))
|
||||
|
||||
|
||||
;; Converteer naar opus indien nodig en flac.
|
||||
(define (to-opus base-path path info)
|
||||
(when (and (needs-processing? path info)
|
||||
@@ -234,28 +246,49 @@
|
||||
(set! processed-opus (+ processed-opus 1))
|
||||
(info-am "Converting flac to opus: ~a" opus-file)
|
||||
(rep-opus
|
||||
(format "Converting flac to opus: ~a" (basename opus-file)))
|
||||
(with-handlers ([exn? (λ (e)
|
||||
(set! failed-converts (+ failed-converts 1))
|
||||
(err-am "Conversion of ~a: ~a" path e))])
|
||||
(unless (directory-exists? (basedir opus-file))
|
||||
(make-directory* (basedir opus-file)))
|
||||
(if (convert-to-opus path opus-file ini)
|
||||
(format "Converting flac to opus in thread: ~a" (basename opus-file)))
|
||||
|
||||
|
||||
(let loop ()
|
||||
(if (= jobs max-jobs)
|
||||
(begin
|
||||
(set! converted-files (+ converted-files 1))
|
||||
(info-am " Converted ~a" converted-files)
|
||||
)
|
||||
(sleep 0.1)
|
||||
(loop))
|
||||
(begin
|
||||
(info-am " CONVERSION PROBLEM")
|
||||
(rep-opus " Conversion failed!")
|
||||
(set! failed-converts (+ failed-converts 1))
|
||||
(set! job-nr (+ job-nr 1))
|
||||
(set! jobs (+ jobs 1))
|
||||
(let ((jobnr job-nr))
|
||||
(thread
|
||||
(λ ()
|
||||
(with-handlers ([exn? (λ (e)
|
||||
(set! failed-converts (+ failed-converts 1))
|
||||
(err-am "Conversion of ~a: ~a" path e))])
|
||||
(unless (directory-exists? (basedir opus-file))
|
||||
(make-directory* (basedir opus-file)))
|
||||
(info-am " Starting conversion job ~a" jobnr)
|
||||
(if (convert-to-opus path opus-file ini)
|
||||
(begin
|
||||
(set! converted-files (+ converted-files 1))
|
||||
(info-am " Converted ~a, job-nr = ~a" converted-files jobnr)
|
||||
)
|
||||
(begin
|
||||
(info-am " CONVERSION PROBLEM, job-nr = ~a" jobnr)
|
||||
(rep-opus " Conversion failed!")
|
||||
(set! failed-converts (+ failed-converts 1))
|
||||
)
|
||||
)
|
||||
(set! jobs (- jobs 1))
|
||||
)
|
||||
)
|
||||
#:pool 'own
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
))
|
||||
(values base-path path info))
|
||||
|
||||
;; Kopieer bestanden rechtstreeks indien nodig en geen flac
|
||||
@@ -300,10 +333,27 @@
|
||||
(values base-path path info))
|
||||
|
||||
(define (target-tree-cleaner base-path path info)
|
||||
(if (eq? (hash-ref info 'type #f) 'dir)
|
||||
(set! dirs-in-target (+ dirs-in-target 1))
|
||||
(set! files-in-target (+ files-in-target 1)))
|
||||
|
||||
(when (or (and
|
||||
(= (remainder dirs-in-target 100) 0)
|
||||
(> (quotient dirs-in-target 100) last-dirs-in-target))
|
||||
(= (remainder files-in-target 1000) 0))
|
||||
(set! last-dirs-in-target (quotient dirs-in-target 100))
|
||||
(info-am "Files in target checked: ~a, dirs: ~a" files-in-target dirs-in-target)
|
||||
(sync-log-am)
|
||||
)
|
||||
(let ((normalized-sub-path (hash-ref info 'path)))
|
||||
(when (opus? info)
|
||||
(set! normalized-sub-path (path-replace-extension normalized-sub-path #".flac")))
|
||||
(unless (store-exists? file-db-store normalized-sub-path)
|
||||
(set! not-in-source (+ not-in-source 1))))
|
||||
(values base-path path info))
|
||||
(info-am "Not in source: ~a" normalized-sub-path)
|
||||
(delete-directory/files path #:must-exist? #f)
|
||||
(sync-log-am)
|
||||
(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)
|
||||
@@ -323,8 +373,8 @@
|
||||
(hash-set! processed-kind ext n)))
|
||||
)
|
||||
|
||||
(when (or (= (remainder processed-dirs 10) 0)
|
||||
(= (remainder processed-files 250) 0))
|
||||
(when (or (= (remainder processed-dirs 100) 0)
|
||||
(= (remainder processed-files 1000) 0))
|
||||
(unless (= dirs-logged processed-dirs)
|
||||
(set! dirs-logged processed-dirs)
|
||||
(info-am (format "processed dirs: ~a, files: ~a, kinds: ~a, unknown kinds: ~a"
|
||||
@@ -340,6 +390,7 @@
|
||||
(map (λ (ext) (symbol->string ext)) unknown-exts)
|
||||
", ")
|
||||
))
|
||||
(sync-log-am)
|
||||
))
|
||||
|
||||
(when (flac-id3? info)
|
||||
@@ -375,6 +426,8 @@
|
||||
(format "Copied files : ~a" copied-files)
|
||||
(format "Failed convert : ~a" failed-converts)
|
||||
(format "Failed copies : ~a" failed-copies)
|
||||
(format "Files in target: ~a" files-in-target)
|
||||
(format "Dirs in target : ~a" dirs-in-target)
|
||||
(format "Not in source : ~a" not-in-source)
|
||||
))
|
||||
(subj (format "Audio manager report d.d. ~a" (date->yyyy-mm-dd (now))))
|
||||
@@ -409,6 +462,14 @@
|
||||
(let-values (((base-path path info) (fw)))
|
||||
(if (eq? info #f)
|
||||
(begin
|
||||
; Wait for all conversions to finish
|
||||
(let loop ()
|
||||
(if (= jobs 0)
|
||||
#t
|
||||
(begin
|
||||
(sleep 0.1)
|
||||
(loop))))
|
||||
; Process Rest.
|
||||
(info-am "Finished walking music library")
|
||||
;; Cleanup files in target, not in source
|
||||
(info-am "Checking files in target, not in source")
|
||||
@@ -416,7 +477,9 @@
|
||||
(let loop1 ()
|
||||
(let-values (((base-path path info) (fwt)))
|
||||
(if (eq? info #f)
|
||||
(info-am "Target check finished")
|
||||
(begin
|
||||
(info-am "Target check finished, not in source: ~a" not-in-source)
|
||||
(info-am "Files in target checked: ~a" files-in-target))
|
||||
(loop1)))))
|
||||
(info-am "Closing store")
|
||||
(store-close file-db-store)
|
||||
|
||||
Reference in New Issue
Block a user