| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- (in-package :cl-user)
- (defpackage chad-music.utils
- (:use :cl #:audio-streams #:alexandria)
- (:export #:*standard-optimize-settings*
- #:text-tag
- #:bit-rate
- #:is-vbr
- #:duration
- #:publisher
- #:country))
- (in-package :chad-music.utils)
- (eval-when (:compile-toplevel :load-toplevel :execute)
- #+dbg
- (defvar *standard-optimize-settings* '(optimize (debug 3)))
- #-dbg
- (defvar *standard-optimize-settings* '(optimize (speed 3) (safety 0) (space 0) (debug 0))))
- (defgeneric text-tag (stream desc) (:method ((object t) desc) nil))
- (defmethod text-tag ((mp3 id3:mp3-file) desc)
- (declare #.*standard-optimize-settings*)
- (loop for frame in (id3:get-frames mp3 '("TXXX"))
- when (string-equal (id3:desc frame) desc)
- do (return-from text-tag (id3:val frame))))
- (defgeneric bit-rate (stream) (:method ((object t)) nil))
- (defgeneric is-vbr (stream) (:method ((object t)) nil))
- (defgeneric duration (stream) (:method ((object t)) nil))
- (defgeneric publisher (stream) (:method ((object t)) nil))
- (defgeneric country (stream) (:method ((object t)) nil))
- (defmethod bit-rate ((mp3 id3:mp3-file))
- (let ((info (id3:audio-info mp3)))
- (when info
- (round (mpeg::bit-rate info) 1000))))
- (defmethod is-vbr ((mp3 id3:mp3-file))
- (let ((info (id3:audio-info mp3)))
- (when info
- (mpeg::is-vbr info))))
- (defmethod duration ((mp3 id3:mp3-file))
- (let ((info (id3:audio-info mp3)))
- (when info
- (mpeg::len info))))
- (defmethod publisher ((mp3 id3:mp3-file))
- (declare #.utils:*standard-optimize-settings*)
- (let ((frames (id3:get-frames mp3 '("TPUB" "TPB"))))
- (when frames
- (return-from publisher (id3:info (first frames)))))
- nil)
- (defmethod country ((mp3 id3:mp3-file))
- (text-tag mp3 "MusicBrainz Album Release Country"))
- (defmethod bit-rate ((m4a m4a:mp4-file))
- (let ((info (m4a:audio-info m4a)))
- (when info
- (round (m4a::avg-bit-rate info) 1000))))
- (defmethod duration ((m4a m4a:mp4-file))
- (let ((info (m4a:audio-info m4a)))
- (when info
- (m4a::seconds info))))
|