Permalink
Browse files

grokpodcast baixando arquivos no windows

  • Loading branch information...
1 parent 81a88ef commit 6818d86c1dac9fc9bed21fc66fc7555383ed334c @pbalduino committed Feb 10, 2014
Showing with 37 additions and 8 deletions.
  1. +37 −8 09/grokpodcast/src/grokpodcast/core.clj
@@ -1,13 +1,42 @@
(ns grokpodcast.core
- (:require [clojure.pprint :as pp]
- [net.cgrand.enlive-html :as en]))
+ (:require [clojure.java.io :as io]
+ [clojure.pprint :as pp]
+ [clojure.string :as str]
+ [net.cgrand.enlive-html :as en])
+ (:import [java.net URL]))
-(def file-dir "C:\\Documents and Settings\\pbalduino\\Meus documentos\\grokpodcast")
+(def file-dir "C:\\Documents and Settings\\pbalduino\\Meus documentos\\grokpodcast\\")
-(defn- get-links [url]
- "meh")
+(defn- get-archive [url]
+ (map
+ #(str "http://www.grokpodcast.com" ((% :attrs) :href))
+ (-> url
+ URL.
+ en/html-resource
+ (en/select [:section#episode-archive :a]))))
+
+(defn- get-file-link [episode-url]
+ (let [link (-> episode-url
+ URL.
+ en/html-resource
+ (en/select [:section#podcast-infos :a])
+ first)]
+ ((link :attrs) :href)))
+
+(defn- download-file [episode-url]
+ (let [link (get-file-link episode-url)
+ filename (-> link
+ (str/split #"/")
+ last)
+ filepath (str file-dir filename)]
+ (when-not (. (io/file filepath) exists)
+ (with-open [in (io/input-stream link)
+ out (io/output-stream (str file-dir filename))]
+ (println "Baixando" filename)
+ (io/copy in out)
+ (println " Concluido" filename)))))
(defn -main [& args]
- (pp/pprint
- (-> "http://www.grokpodcast.com/arquivo/"
- get-links)))
+ (doall
+ (pmap download-file (get-archive "http://www.grokpodcast.com/arquivo/")))
+ (shutdown-agents))

0 comments on commit 6818d86

Please sign in to comment.