src/newseasons/itunes.clj @ 89f24149ecd7

Start a refresh loop.
author Steve Losh <steve@stevelosh.com>
date Mon, 03 Oct 2011 21:28:10 -0400
parents d6f1f9d14b82
children 279de613dd93
(ns newseasons.itunes
  (:require [clj-http.client :as client]) 
  (:use newseasons.utils)
  (:use [cheshire.core :only (parse-string)]))


(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 entity]
  ((parse-string (:body (client/get "http://itunes.apple.com/lookup"
                                    {:query-params {field id
                                                    "entity" entity}})))
     "results"))

(defn itunes-lookup-seasons [id]
  (let [results (itunes-lookup "id" id "tvSeason")]
    (last (sort-maps-by (filter #(% "collectionName")
                                results)
                        "releaseDate"))))