# HG changeset patch # User Steve Losh # Date 1317258092 14400 # Node ID 6c5f457125353c42f19c7c3a1f1dfc61abf11c22 # Parent e10e3e94781da52318cb4046773e374d237f07f7 Refactor itunes. diff -r e10e3e94781d -r 6c5f45712535 src/newseasons/views/main.clj --- a/src/newseasons/views/main.clj Wed Sep 28 20:51:41 2011 -0400 +++ b/src/newseasons/views/main.clj Wed Sep 28 21:01:32 2011 -0400 @@ -8,6 +8,27 @@ (def email-regex #"[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}") +(defn itunes-search [params] + ((parse-string (:body (client/get "http://itunes.apple.com/search" + {:query-params params}))) + "results")) + +(defn itunes-search-show [query] + (itunes-search {"term" query + "media" "tvShow" + "entity" "tvSeason" + "attribute" "showTerm"})) + + +(defn itunes-lookup [field id] + ((parse-string (:body (client/get "http://itunes.apple.com/search" + {:query-params {field id}}))) + "results")) + +(defn itunes-lookup-artist [id] + (itunes-lookup "id" id)) + + ; Home ------------------------------------------------------------------------ (defpage [:get "/"] [] (t/home)) @@ -22,17 +43,10 @@ ; Search ---------------------------------------------------------------------- -(defn search-itunes [query] - ((parse-string (:body (client/get "http://itunes.apple.com/search" - {:query-params {"term" query - "media" "tvShow" - "entity" "tvSeason" - "attribute" "showTerm"}}))) - "results")) (defpage [:get "/search"] {:keys [query]} ; TODO: Images. - (let [results (search-itunes query) + (let [results (itunes-search-show query) artists (distinct (map #(select-keys % ["artistName" "artistId" "artistViewUrl"]) results))] (t/search query artists)))