From ae432628f6b65e0bfd70f2c1ee5bb55ed939cf44 Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Wed, 25 Feb 2026 11:35:56 +0100 Subject: [PATCH] - --- libtag/taglib.rkt | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/libtag/taglib.rkt b/libtag/taglib.rkt index 89e1d24..ef56a3c 100644 --- a/libtag/taglib.rkt +++ b/libtag/taglib.rkt @@ -2,6 +2,7 @@ (require "taglib-ffi.rkt" "../utils/utils.rkt" + racket/string racket/draw) (provide id3-tags @@ -26,6 +27,11 @@ tags-picture tags-picture->bitmap + tags-picture->file + tags-picture->kind + tags-picture->mimetype + tags-picture->size + tags-picture->ext tags->hash @@ -222,7 +228,49 @@ (btm (read-bitmap in))) (close-input-port in) btm)))) - + + (define (tags-picture->kind tags) + (let ((p (tags-picture tags))) + (if (eq? p #f) + #f + (id3-picture-kind p)))) + + (define (tags-picture->mimetype tags) + (let ((p (tags-picture tags))) + (if (eq? p #f) + #f + (id3-picture-mimetype p)))) + + (define (tags-picture->ext tags) + (let ((mt (tags-picture->mimetype tags))) + (cond + ((or (string-suffix? mt "/jpeg") (string-suffix? mt "/jpg")) + 'jpg) + ((string-suffix? mt "/png") + 'png) + (else (error (format "mimetype not supported: ~a" mt))) + ) + )) + + (define (tags-picture->size tags) + (let ((p (tags-picture tags))) + (if (eq? p #f) + #f + (id3-picture-size p)))) + + (define (tags-picture->file tags path) + (let ((p (tags-picture tags))) + (if (eq? p #f) + #f + (let* ((in (open-input-bytes (id3-picture-bytes p))) + (fh (open-output-file path #:mode 'binary #:exists 'replace))) + (let ((bytes (read-bytes 16384 in))) + (while (and (not (eof-object? bytes)) (> (bytes-length bytes) 0)) + (write-bytes bytes fh) + (set! bytes (read-bytes 16384 in)))) + (close-output-port fh) + (close-input-port in) + #t)))) ); end of module