Skip to content

Instantly share code, notes, and snippets.

@telent
Created March 3, 2012 22:03
Show Gist options
  • Save telent/1968570 to your computer and use it in GitHub Desktop.
Save telent/1968570 to your computer and use it in GitHub Desktop.
Audio (mp3/flac/etc) tag support for Clojure via JAudiotagger
(ns onelouder.core
(:import [org.jaudiotagger.audio AudioFileIO]
[org.jaudiotagger.tag FieldKey]))
(defn tags [file]
(let [fields (apply conj {} (map (fn [n] [(keyword (. (. n toString) toLowerCase)) n]) (. FieldKey values)))
tag (. file (getTag))]
(apply conj {}
(filter (fn [[name val]] (and val (not (empty? val))))
(map (fn [[name val]]
[name (seq (map #(. % getContent) (. tag (getFields val))))])
fields)))))
(defn audioheader [file]
(bean (. file (getAudioHeader))))
(defn metadata [filename]
(let [file (AudioFileIO/read (new java.io.File filename))]
{:tags (tags file)
:audioheader (audioheader file)}))
(defproject onelouder "1.0.0-SNAPSHOT"
:description "Audio (mp3/flac/etc) tag support for Clojure via JAudiotagger"
:dependencies [[org.clojure/clojure "1.3.0"]
[org/jaudiotagger "2.0.3"]])
@telent
Copy link
Author

telent commented Mar 3, 2012

The :tags map values are deliberately lists, because the spec apparently allows for multiple tags with the same name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment