1. Jeffrey Stoffers
  2. hb-client


Jeffrey Stoffers  committed a803756

Added some bad comments and fixed an error in the parser.

Fixed an error that cause the parser to lose metadata for files that had more than one download.

  • Participants
  • Parent commits ebb4562
  • Branches master

Comments (0)

Files changed (2)

File src/hb_client/.#core.clj


File src/hb_client/core.clj

View file
             [digest :as digest]
             [clojure.java.io :as io]))
-(def hb-login-url "https://www.humblebundle.com/login")
-(def hb-games-url "https://www.humblebundle.com/home")
-(def username "")
-(def password "")
-(def hb-dl-path "")
+(defonce hb-login-url "https://www.humblebundle.com/login")
+(defonce hb-games-url "https://www.humblebundle.com/home")
 (defn enlive-parse
+  "Parse html with enlive"
   (html/html-resource (java.io.StringReader. s)))
 (defn retrieve-games-page
-  []
+  "Log into and grab the humble bundle library page"
+  [username password]
   (binding [clj-http.core/*cookie-store* (clj-http.cookies/cookie-store)]
     (client/post hb-login-url
                  {:form-params {:username username :password password}})
     (client/get hb-games-url)))
-(defonce eh (enlive-parse (:body (retrieve-games-page))))
-(defonce rows (html/select eh [:div.row]))
 (defn parse-icn
+  "Parse the game icon url from the hmtl"
   (get-in (first (html/select coll [:div.icn :img])) [:attrs :src]))
 (defn parse-title
+  "Parse the game title from the html"
   (html/text (first (html/select coll [:div.gameinfo :div.title :a]))))
-(defn parse-subtitle
+(defn parse-developer
+  "Parse the developer/author from the html"
   (html/text (first (html/select coll [:div.gameinfo :div.subtitle :a]))))
 (defn parse-dl-type
+  "Get the download category of the download"
   (second (clojure.string/split (get-in coll [:attrs :class]) #" ")))
+(defn parse-dl-title
+  [coll]
+  (html/text (first (html/select coll [:div.flexbtn :a.a]))))
 (defn parse-dl-size
   (first (:content (first (html/select coll [:div.dlsize :span.mbs])))))
   (get-in (first (html/select coll [:div.flexbtn :a.a])) [:attrs :data-bt]))
-(defn parse-dl-title
-  [coll]
-  (html/text (first (html/select coll [:div.flexbtn :a.a]))))
 (defn parse-download
+  "Parse a download row of data for the metadata"
-  (first (merge (map (fn [coll]
-                       {:size (parse-dl-size coll)
-                        :md5 (parse-dl-md5 coll)
-                        :web (parse-dl-web coll)
-                        :torrent (parse-dl-torrent coll)
-                        :title (parse-dl-title coll)
-                        :date (parse-dl-date coll)})
-                     (html/select rows [:div.download])))))
+  (map (fn [coll]
+         {:size (parse-dl-size coll)
+          :md5 (parse-dl-md5 coll)
+          :web (parse-dl-web coll)
+          :torrent (parse-dl-torrent coll)
+          :title (parse-dl-title coll)
+          :date (parse-dl-date coll)})
+       (html/select rows [:div.download])))
 (defn parse-downloads
+  "Given an html row of humble bundle game data parse all the download types"
   (merge (map (fn [coll]
                 {:dl-type (parse-dl-type coll)
               (html/select row [:div.downloads]))))
 (defn parse-row
+  "Given a list of humble bundle game rows return a map of game metadata"
    (fn [coll]
      {:title (parse-title coll)
-      :subtitle (parse-subtitle coll)
+      :developer (parse-developer coll)
       :icon (parse-icn coll)
       :downloads (parse-downloads coll)})
 (defn parse-downloaded-md5
-  (map (fn [f] {:file f :md5 (digest/md5 f)}) (filter (comp not directory?) (file-seq (io/file hb-dl-path)))))
-(defonce humble-data (parse-row rows))
-(defonce file-data (parse-downloaded-md5))
+  (map (fn [f]
+         {:file f :md5 (digest/md5 f)})
+       (filter (comp not directory?) (file-seq (io/file hb-dl-path)))))
 (defn -main
-  []
-  (:body (retrieve-games-page)))
+  [username password]
+  (let [library (-> (retrieve-games-page username password)
+                    (get-in [:body])
+                    (enlive-parse)
+                    (html/select [:div#regular_download_list])
+                    (html/select [:div.row])
+                    parse-row)]
+    ))