-
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user