Walton Hoops committed 3b80cf6

add extract-tags function

Comments (0)

Files changed (3)

     (use-package :taglib)
+    ;;; Easy way:
+    (extract-tags "09 My Generation.mp3")
+    ;;; result
+    (:TRACK 9 :YEAR 1994 :GENRE "Rock" :COMMENT ""
+     :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
 	      `(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))))
+	   #:extract-tags
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.