Skip to content

Instantly share code, notes, and snippets.

Created December 26, 2011 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1521996 to your computer and use it in GitHub Desktop.
Save anonymous/1521996 to your computer and use it in GitHub Desktop.
(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