Skip to content

Instantly share code, notes, and snippets.

@attentive
Last active December 1, 2022 11:01
Show Gist options
  • Save attentive/c83856f181aa0a65293524241d533b32 to your computer and use it in GitHub Desktop.
Save attentive/c83856f181aa0a65293524241d533b32 to your computer and use it in GitHub Desktop.
Example of MP3 metadata access in Clojure via Java interop and JAudioTagger
; 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