Created
December 26, 2011 19:43
-
-
Save anonymous/1521996 to your computer and use it in GitHub Desktop.
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
(ns jwget.core | |
(:gen-class) | |
(:require | |
[clojure.contrib.http.agent :as h] | |
[clojure.contrib.duck-streams :as ds] | |
[clojure.contrib.str-utils2 :as s]) | |
(:import [java.io FileOutputStream])) | |
(defn download | |
[url] | |
(h/http-agent url | |
:handler (fn [agnt] | |
(with-open [w (FileOutputStream. | |
(let [fullname (last (s/split url #"/")) | |
[filename ext] (s/split fullname #"\.")] | |
(str (name (gensym filename)) "." ext)))] | |
(ds/copy (h/stream agnt) w))))) | |
(defn download-all | |
[urls] | |
(doseq [url urls] | |
(download url))) | |
(defn -main [& args] | |
(download-all args)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment