Created
December 15, 2009 15:53
-
-
Save shoover/257035 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns mrssxml | |
"Prints out an mrss xml playlist for a directory of mp3s. | |
Usage: | |
java -cp clojure-1.0.0.jar:clojure-contrib-1.0-compat.jar clojure.main \\ | |
~/mrssxml.clj some-dir > playlist.xml" | |
(:use [clojure.contrib prxml]) | |
(:require [clojure.contrib.str-utils2 :as s] | |
[clojure.contrib.java-utils :as java] | |
[clojure.contrib.command-line :as cl])) | |
(defn mp3s-in-dir | |
"Returns the mp3 filenames as strings." | |
[dir] | |
(filter #(.endsWith % ".mp3") | |
(map #(.getName %) (file-seq (java/as-file dir))))) | |
(defn generate | |
"Generates the xml and prints to *out*" | |
[mp3s title link] | |
(binding [*prxml-indent* 2] | |
(prxml [:rss {:version "2.0" | |
:xmlns:media "http://search.yahoo.com/mrss/"} | |
[:channel | |
(if title [:title title]) | |
(if link [:link link]) | |
(map (fn [mp3] | |
[:item | |
[:title (s/replace mp3 #"\.mp3$" "")] | |
(if link [:link link]) | |
[:media:content {:url (java.net.URI. nil nil mp3 nil) | |
:type "audio/mpeg"}]]) | |
mp3s)]]))) | |
(cl/with-command-line *command-line-args* | |
"Prints out an mrss xml playlist for a directory of mp3s" | |
[[title "Channel title"] | |
[link "Channel link"] | |
dirs] | |
(generate (mp3s-in-dir (first dirs)) title link)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment