Skip to content

Instantly share code, notes, and snippets.

@zachpendleton
Created July 5, 2012 02:26
Show Gist options
  • Save zachpendleton/3050669 to your computer and use it in GitHub Desktop.
Save zachpendleton/3050669 to your computer and use it in GitHub Desktop.
Lazy seq of a user's Last.fm tracks
(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