Commits

Walton Hoops committed 60a4f56

add extract-tags function

Comments (0)

Files changed (3)

 
     :::lisp
     (use-package :taglib)
+
+    ;;; Easy way:
+    (extract-tags "/home/whoops/09 My Generation.mp3")
+    ;;; result
+    (:TRACK 9 :YEAR 1994 :GENRE "Rock" :COMMENT "Amazon.com 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)))
 	      `(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))))
 	   #:tag-genre
 	   #:tag-track
 	   #:tag-year
+	   #:extract-tags
 	   #:audio-length
 	   #:audio-bitrate
 	   #:audio-samplerate