Last active
December 1, 2022 11:01
-
-
Save attentive/c83856f181aa0a65293524241d533b32 to your computer and use it in GitHub Desktop.
Example of MP3 metadata access in Clojure via Java interop and JAudioTagger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; I fooled around a bit with this years ago, creating this Gist to replace the defunct repository on my personal GitHub. | |
; This is just standard Clojure Java interop, you can find out a bit more about JAudioTagger here if you're interested: | |
; | |
; https://search.maven.org/artifact/net.jthink/jaudiotagger | |
(ns wat.core | |
(:import (org.jaudiotagger.audio AudioFileIO AudioFile) | |
(org.jaudiotagger.tag FieldKey) | |
(java.io File))) | |
(def wat-keys | |
"List the distinct valid field keys available to query in the jaudiotagger unified format API." | |
(set (sort (map #(-> %1 .toString keyword) (FieldKey/values))))) | |
(defn valid-wat-key [k] | |
"Determine if a field key is valid." | |
(contains? wat-keys k)) | |
(defn wat-val [audiofile k] | |
"Get the first value of a specific wat key found in a tag." | |
(-> audiofile .getTag (.getFirst (FieldKey/valueOf (name k))))) | |
(defn wat-vals [audiofile] | |
"List all wat keys and their vals in an audiofile." | |
(into {} (for [k wat-keys] [k (wat-val audiofile k)]))) | |
(defn read-audiofile [filename] | |
"Read an audio file." | |
(AudioFileIO/read (java.io.File. filename))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment