Created
July 5, 2012 02:26
-
-
Save zachpendleton/3050669 to your computer and use it in GitHub Desktop.
Lazy seq of a user's Last.fm tracks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns last-fm.track-stream | |
(require [clj-http.client :as client]) | |
(use cheshire.core)) | |
(def api-key "...") | |
(def current-song (atom {})) | |
(def uri "http://ws.audioscrobbler.com/2.0/") | |
(defn next-song [user] | |
(decode | |
(:body (client/get uri {:query-params {:api_key api-key | |
:format "json" | |
:limit 1 | |
:method "user.getRecentTracks" | |
:user user}})))) | |
(defn get-next-song [user] | |
(let [song (next-song user)] | |
(if (= @current-song song) | |
(do | |
(Thread/sleep 5000) | |
(recur user)) | |
(reset! current-song song)))) | |
(defn track-seq [user] | |
(let [track (last-song user)] | |
(lazy-seq (cons track (last-song user))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment