1(import [protocol [commands]]2 [mpd.exceptions [*]]3 [protocol.util :as util])4(require [hy.extra.anaphoric [*]]5 [hy.contrib.walk [let]])67(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 items14 (with (playlist ctx.playback)15 (try16 (ap-each items (.add playlist (util.create-song it)))17 (except [FileNotFoundError]18 (raise MPDNotFoundError))))19 (raise MPDNotFoundError)))))2021;; TODO: Handle case where the delete song is the current song (requires22;; 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 (try27 (.remove ctx.playback (.to-range (first args) (.psize playlist)))28 (except [IndexError]29 (raise MPDBadIndexError))))))3031;; TODO: Respect optional song position argument.32(with-decorator (commands.add "playlistinfo")33 (defn playlist-info [ctx args]34 ctx.playback))