Skip to content

Instantly share code, notes, and snippets.

@yogthos
Last active Mar 19, 2020
Embed
What would you like to do?
#!/usr/bin/env bb
(require '[clojure.java.shell :refer [sh]])
(defn exit [error]
(println error)
(System/exit 1))
(defn open-folder [folder]
(let [folder (some-> folder (io/file))]
(when (nil? folder)
(exit "usage: shufle-play.clj <music folder>"))
(when-not (.exists folder)
(exit (str "music folder not found:" (.getName folder))))
folder))
(defn play-mp3s
([mp3s]
(play-mp3s (shuffle mp3s) []))
([[mp3 & more] played]
(if mp3
(do
(println "playing" (.getName mp3))
(sh "ffplay" "-nodisp" "-autoexit" (.getAbsolutePath mp3))
(recur more (conj played mp3)))
(recur (shuffle played) []))))
(->> (first *command-line-args*)
(open-folder)
(file-seq)
(rest)
(filter #(.endsWith (.getName %) ".mp3"))
(play-mp3s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment