No places.

This commit is contained in:
2026-06-10 08:31:47 +02:00
parent 736638f2a4
commit 930903fb42
7 changed files with 77 additions and 63 deletions
+29 -24
View File
@@ -3,7 +3,6 @@
(require racket/file
racket/list
racket/path
racket/place
racket/string
"util.rkt")
@@ -84,28 +83,34 @@
(tags-save! tags)))
#:mode 'read-write))
(define (convert-flac-to-opus input-path output-path kbps)
(define (delete-file/quiet path)
(with-handlers ([exn:fail? (lambda (_) #f)])
(when (file-exists? path) (delete-file path))))
(define (convert-flac-to-opus input-path output-path kbps
#:progress-callback [progress-callback #f])
(define tmp-path (temp-output-path output-path))
(ensure-parent-directory! tmp-path)
(define worker
(place ch
(define msg (place-channel-get ch))
(define in-file (list-ref msg 0))
(define out-file (list-ref msg 1))
(define kbps (list-ref msg 2))
(with-handlers ([exn:fail? (lambda (e) (place-channel-put ch (list 'error (exn-message e))))])
(define-values (settings properties picture) (source-tags->settings in-file kbps))
(define audio-encode (dynamic-require 'racket-audio/audio-encoder 'audio-encode))
(define result (audio-encode in-file out-file settings #:encoder 'opus #:copy-tags? #f))
(copy-all-tag-properties! out-file properties picture)
(place-channel-put ch (list 'ok result)))))
(place-channel-put worker (list (path->string input-path) (path->string tmp-path) kbps))
(define response (place-channel-get worker))
(cond [(and (pair? response) (eq? (car response) 'ok))
(ensure-parent-directory! output-path)
(rename-file-or-directory tmp-path output-path #t)
(cadr response)]
[else
(when (file-exists? tmp-path) (delete-file tmp-path))
(error 'convert-flac-to-opus "conversion failed for ~a: ~a" input-path
(if (and (pair? response) (pair? (cdr response))) (cadr response) response))]))
(with-handlers ([exn:break?
(lambda (e)
(delete-file/quiet tmp-path)
(raise e))]
[exn:fail?
(lambda (e)
(delete-file/quiet tmp-path)
(error 'convert-flac-to-opus
"conversion failed for ~a: ~a" input-path (exn-message e)))])
(define-values (settings properties picture)
(source-tags->settings (path->string input-path) kbps))
(define audio-encode (dynamic-require 'racket-audio/audio-encoder 'audio-encode))
(define result
(audio-encode (path->string input-path)
(path->string tmp-path)
settings
#:encoder 'opus
#:copy-tags? #f
#:progress-callback progress-callback))
(copy-all-tag-properties! (path->string tmp-path) properties picture)
(ensure-parent-directory! output-path)
(rename-file-or-directory tmp-path output-path #t)
result))