Finding a Playlist

The last of the three URL functions is the simplest. It presents a table listing all the playlists that have been created. Ordinarily users won’t need to use this page, but during development it gives you a useful view into the state of the system. It also provides the mechanism to choose a different playlist—each playlist ID is a link to the playlist page with an explicit playlist-id query parameter, which will then be made sticky by the playlist URL function. Note that you need to acquire the *playlists-lock* to make sure the *playlists* hash table doesn’t change out from under you while you’re iterating over it.

  1. (define-url-function all-playlists (request)
  2. (:mp3-browser-page
  3. (:title "All Playlists")
  4. ((:table :class "all-playlists")
  5. (:table-row "Playlist" "# Songs" "Most recent user agent")
  6. (with-process-lock (*playlists-lock*)
  7. (loop for playlist being the hash-values of *playlists* do
  8. (html
  9. (:table-row
  10. (:a :href (link "playlist" :playlist-id (id playlist)) (:print (id playlist)))
  11. (:print (table-size (songs-table playlist)))
  12. (:print (user-agent playlist)))))))))