mk-music-cd

#588
Raw
Author
Anonymous
Created
Oct. 22, 2022, 8:01 a.m.
Expires
Never
Size
1.4 KB
Hits
34
Syntax
Racket
Private
✗ No
#!/usr/bin/env racket
#|
TODO better error handling
TODO clean up temp files
TODO multi-cd albums
|#
#lang racket

(require tool
         basedir
         dirname)

(current-basedir-program-name "mk-music-cd")

(define (main music-files)
  (define out-dir (writable-runtime-dir))
  (make-directory* out-dir)
  (define tasks (for/list ([f music-files])
                  (define dest (build-path out-dir (path-replace-extension (basename f) #".wav")))
                  (place/context pch
                    ($ `(ffmpeg -loglevel fatal -y "-i" ,f -ac 2 -ar 44100 ,dest) #:output #f)
                    (place-channel-put pch dest))))
  (define wavs (map place-channel-get tasks))

  (info "Done transcoding to .wav")
  (define normalized-wavs (for/list ([w wavs])
                            (define dir (dirname w))
                            (define base (basename w))
                            (define normalized-dir (build-path dir "normalized"))
                            (make-directory* normalized-dir)
                            (build-path normalized-dir base)))
  ;; XXX Use multiple processes ?
  ($ `(ffmpeg-normalize "-o" ,@normalized-wavs "-vn" "-ofmt" wav -ar 44100 ,@wavs))
  (info "Normalized audio.")

  (info "Burning disc...")
  ($ `(cdrecord -nofix -audio -pad ,@normalized-wavs))
  (info "Disc burned."))

(module+ main
  (tool-init! #:logging 'debug)
  (command-line
   #:args music-files
   (main music-files)))