Walton Hoops  committed f56ed1a

add extract-tags function

  • Participants
  • Parent commits 2332fb0

Comments (0)

Files changed (3)

     (use-package :taglib)
+    ;;; Easy way:
+    (extract-tags "09 My Generation.mp3")
+    ;;; result
+    (:TRACK 9 :YEAR 1994 :GENRE "Rock" :COMMENT " Song ID: 205431823"
+     :ALBUM "Thirty Years Of Maximum R&B" :ARTIST "The Who" :TITLE "My Generation")
+    ;;; Longer way:
     (with-tag-file (file "07 - 17.mp3")
       (let ((tag (file-tag file))
             (audio (file-audioproperties file)))
 (*tag-<property>* tag) Returns the given property.  All tag operations are setf-able.  Available accessors are (title album artist genre comment track year)
+(*extract-tags* pathname) Returns a plist of the tags in the given file.
 ### Reading audio information
 (*file-audioproperties* file) returns the audio properties for the given file

File cl-taglib.lisp

 	      `(defun ,function-name (tag)
 		(foreign-funcall ,foreign-name :pointer tag ,type)))
 	  `(defun (setf ,function-name) (value tag)
-	    (foreign-funcall ,foreign-set-name :pointer tag ,type value :void)))))
-(tag-accessor-for :title :string)
-(tag-accessor-for :artist :string)
-(tag-accessor-for :album :string)
-(tag-accessor-for :comment :string)
-(tag-accessor-for :genre :string)
-(tag-accessor-for :year :uint)
-(tag-accessor-for :track :uint)
+	    (foreign-funcall ,foreign-set-name :pointer tag ,type value :void))
+	  `(list ,slot ',function-name))))
+(defparameter *tag-accessors* (list (tag-accessor-for :title :string)
+				    (tag-accessor-for :artist :string)
+				    (tag-accessor-for :album :string)
+				    (tag-accessor-for :comment :string)
+				    (tag-accessor-for :genre :string)
+				    (tag-accessor-for :year :uint)
+				    (tag-accessor-for :track :uint)))
+(defun extract-tags (pathname)
+  (with-tag-file (file pathname)
+    (let ((tag (file-tag file))
+	  (result ()))
+      (dolist (accessor *tag-accessors* result)
+	(push (funcall (cadr accessor) tag) result)
+	(push (car accessor) result)))))
 (defmacro audio-reader-for (slot)
   (let ((function-name (intern (concatenate 'string "AUDIO-" (string slot))))

File package.lisp

+	   #:extract-tags