1(import [protocol [commands]]
2 [mpd.exceptions [*]]
3 [protocol.util :as util])
4(require [hy.extra.anaphoric [*]]
5 [hy.contrib.walk [let]])
6
7(with-decorator (commands.add "add")
8 (defn add [ctx args]
9 (let [items (-> (with [(.transaction (. ctx beets))]
10 (.items (. ctx beets)
11 (.format "path:{}" (first args))))
12 list)]
13 (if items
14 (with (playlist ctx.playback)
15 (try
16 (ap-each items (.add playlist (util.create-song it)))
17 (except [FileNotFoundError]
18 (raise MPDNotFoundError))))
19 (raise MPDNotFoundError)))))
20
21;; TODO: Handle case where the delete song is the current song (requires
22;; player to skip to the next song in the playlist or stop if none).
23(with-decorator (commands.add "delete")
24 (defn delete [ctx args]
25 (with (playlist ctx.playback)
26 (try
27 (.remove ctx.playback (.to-range (first args) (.psize playlist)))
28 (except [IndexError]
29 (raise MPDBadIndexError))))))
30
31;; TODO: Respect optional song position argument.
32(with-decorator (commands.add "playlistinfo")
33 (defn playlist-info [ctx args]
34 ctx.playback))