This commit is contained in:
2026-02-25 11:35:56 +01:00
parent 4a9aa63f92
commit ae432628f6

View File

@@ -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