Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 252 lines (190 sloc) 6.89 kb
94d54450 »
2008-09-04 Cleanup.
1 ;;; -*- Mode: Lisp -*-
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
2
3 ;;;; MPD Commands
4
5 ;;; This software is in the public domain and is
6 ;;; provided with absolutely no warranty.
7
8 (in-package :mpd)
9
10 (defcommand password (password)
11 "Authentication."
a0f7b041 »
2008-09-04 Argument checking.
12 (check-args string password)
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
13 (send "password" password))
14
15 (defcommand disconnect ()
16 "Close connection."
17 (socket-close connection))
18
19 (defcommand now-playing ()
20 "Return instance of playlist with current song."
5b0e9b16 »
2008-09-01 Various changes.
21 (let ((track (send "currentsong")))
22 (when track
23 (make-track track 'playlist))))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
24
98aca3cd »
2008-07-15 Add commands.
25 (defcommand disable-output (id)
a0f7b041 »
2008-09-04 Argument checking.
26 (check-args integer id)
98aca3cd »
2008-07-15 Add commands.
27 (send "disableoutput" id))
28
29 (defcommand enable-output (id)
a0f7b041 »
2008-09-04 Argument checking.
30 (check-args integer id)
98aca3cd »
2008-07-15 Add commands.
31 (send "enableoutput" id))
32
33 (defcommand ping ()
34 "Send ping to MPD."
35 (send "ping"))
36
37 (defcommand kill ()
38 "Stop MPD in a safe way."
39 (send "kill"))
40
41 (defcommand status ()
42 "Return status of MPD."
43 (split-values (send "status")))
44
45 (defcommand stats ()
46 "Return statisics."
47 (split-values (send "stats")))
48
49 (defcommand outputs ()
50 "Return information about all outputs."
51 (split-values (send "outputs")))
52
53 (defcommand commands ()
54 "Return list of available commands."
55 (filter-keys (send "commands")))
56
57 (defcommand not-commands ()
58 "Return list of commands to which the current user does not have access."
59 (filter-keys
60 (send "notcommands")))
61
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
62 ;;; Control
63
64 (defcommand pause ()
65 "Toggle pause / resume playing."
66 (send "pause"))
67
68 (defcommand play (&optional song-number)
a0f7b041 »
2008-09-04 Argument checking.
69 (check-args (or integer null) song-number)
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
70 "Begin playing the playlist starting from song-number, default is 0."
71 (send "play" song-number))
72
73 (defcommand stop ()
74 "Stop playing."
75 (send "stop"))
76
77 (defcommand next ()
78 "Play next track in the playlist."
79 (send "next"))
80
81 (defcommand previous ()
82 "Play previous track in the playlist."
83 (send "previous"))
84
85 ;; Playlist
86
fff275ea »
2008-09-01 Added: shuffle, list-playlist.
87 (defcommand list-playlist (name)
88 "List files in the playlist `name'"
a0f7b041 »
2008-09-04 Argument checking.
89 (check-args string name)
90 (filter-keys (send "listplaylist" name)))
fff275ea »
2008-09-01 Added: shuffle, list-playlist.
91
92 (defcommand list-playlist-info (name)
93 "List metadata of tracks in the playlist `name'"
a0f7b041 »
2008-09-04 Argument checking.
94 (check-args string name)
95 (parse-list (send "listplaylistinfo" name) 'playlist))
fff275ea »
2008-09-01 Added: shuffle, list-playlist.
96
98aca3cd »
2008-07-15 Add commands.
97 (defcommand playlist ()
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
98 "Return list of files in the current playlist."
99 (filter-keys (send "playlist")))
100
101 (defcommand clear-playlist ()
102 "Clear the current playlist."
103 (send "clear"))
104
105 (defcommand save-playlist (filename)
106 "Save the current playlist to the file in the playlist directory."
a0f7b041 »
2008-09-04 Argument checking.
107 (check-args string filename)
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
108 (send "save" filename))
109
110 (defcommand load-playlist (filename)
111 "Load playlist from file."
a0f7b041 »
2008-09-04 Argument checking.
112 (check-args string filename)
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
113 (send "load" filename))
114
115 (defcommand rename-playlist (name new-name)
116 "Rename playlist."
a0f7b041 »
2008-09-04 Argument checking.
117 (check-args string name new-name)
8dae2cb4 »
2008-08-29 Added argument checking.
118 (unless (equal name new-name)
119 (send "rename" name new-name)))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
120
121 (defcommand playlist-info (&optional id)
122 "Return content of the current playlist."
a0f7b041 »
2008-09-04 Argument checking.
123 (check-args (or integer null) id)
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
124 (if id
b5c305f8 »
2008-08-28 Many changes.
125 (make-track (send "playlistinfo" id) 'playlist)
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
126 (parse-list (send "playlistinfo") 'playlist)))
127
98aca3cd »
2008-07-15 Add commands.
128 (defgeneric add (connection what)
129 (:documentation "Add file or directory to the current playlist."))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
130
98aca3cd »
2008-07-15 Add commands.
131 (defmethod-command add ((what track))
b5c305f8 »
2008-08-28 Many changes.
132 (add connection (file what)))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
133
98aca3cd »
2008-07-15 Add commands.
134 (defmethod-command add ((what string))
26c2d20d »
2008-09-14 Small changes.
135 (check-args string what)
98aca3cd »
2008-07-15 Add commands.
136 (send "add" what))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
137
98aca3cd »
2008-07-15 Add commands.
138 (defgeneric add-id (connection what)
b5c305f8 »
2008-08-28 Many changes.
139 (:documentation "Like add, but returns a id."))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
140
98aca3cd »
2008-07-15 Add commands.
141 (defmethod-command add-id ((what track))
b5c305f8 »
2008-08-28 Many changes.
142 (add connection (file what)))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
143
98aca3cd »
2008-07-15 Add commands.
144 (defmethod-command add-id ((what string))
26c2d20d »
2008-09-14 Small changes.
145 (check-args string what)
98aca3cd »
2008-07-15 Add commands.
146 (car (filter-keys (send "addid" what))))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
147
98aca3cd »
2008-07-15 Add commands.
148 (defcommand move (from to)
149 "Move track from `from' to `to' in the playlist."
a0f7b041 »
2008-09-04 Argument checking.
150 (check-args integer from to)
50ffc5fd »
2008-09-01 Add swap and swap-id.
151 (unless (= from to)
a0f7b041 »
2008-09-04 Argument checking.
152 (send "move" from to)))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
153
98aca3cd »
2008-07-15 Add commands.
154 (defgeneric move-id (connection id to)
155 (:documentation "Move track with `id' to `to' in the playlist."))
156
8dae2cb4 »
2008-08-29 Added argument checking.
157 (defmethod-command move-id ((track playlist) (to integer))
b5c305f8 »
2008-08-28 Many changes.
158 (move-id connection (id track) to))
98aca3cd »
2008-07-15 Add commands.
159
8dae2cb4 »
2008-08-29 Added argument checking.
160 (defmethod-command move-id ((id integer) (to integer))
98aca3cd »
2008-07-15 Add commands.
161 (send "moveid" id to))
162
50ffc5fd »
2008-09-01 Add swap and swap-id.
163 (defcommand swap (first second)
164 "Swap positions of two tracks."
a0f7b041 »
2008-09-04 Argument checking.
165 (check-args integer first second)
50ffc5fd »
2008-09-01 Add swap and swap-id.
166 (unless (= first second)
a0f7b041 »
2008-09-04 Argument checking.
167 (send "swap" first second)))
50ffc5fd »
2008-09-01 Add swap and swap-id.
168
169 (defgeneric swap-id (connection first second)
170 (:documentation "Swap positions of two tracks by id."))
171
172 (defmethod-command swap-id ((first playlist) (second playlist))
173 (swap-id connection (id first) (id second)))
174
175 (defmethod-command swap-id ((first integer) (second integer))
176 (send "swap" first second))
177
98aca3cd »
2008-07-15 Add commands.
178 (defcommand delete-track (number)
179 "Delete track from playlist."
a0f7b041 »
2008-09-04 Argument checking.
180 (check-args integer number)
98aca3cd »
2008-07-15 Add commands.
181 (send "delete" number))
182
183 (defgeneric delete-id (connection id)
184 (:documentation "Delete track with `id' from playlist."))
185
186 (defmethod-command delete-id ((id playlist))
b5c305f8 »
2008-08-28 Many changes.
187 (delete-id connection (id id)))
98aca3cd »
2008-07-15 Add commands.
188
8dae2cb4 »
2008-08-29 Added argument checking.
189 (defmethod-command delete-id ((id integer))
98aca3cd »
2008-07-15 Add commands.
190 (send "deleteid" id))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
191
fff275ea »
2008-09-01 Added: shuffle, list-playlist.
192 (defcommand shuffle ()
193 "Shuffle the current playlist."
194 (send "shuffle"))
195
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
196 ;;; Database
197
198 (defcommand update (&optional path)
199 "Scan directory for music files and add them to the database."
200 (send "update" path))
201
26c2d20d »
2008-09-14 Small changes.
202 (defcommand find-tracks (type what)
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
203 "Find tracks in the database with a case sensitive, exact match."
5b0e9b16 »
2008-09-01 Various changes.
204 (assert (member type +tag-types+))
a0f7b041 »
2008-09-04 Argument checking.
205 (check-args string what)
206 (parse-list (send "find" type what) 'track))
98aca3cd »
2008-07-15 Add commands.
207
26c2d20d »
2008-09-14 Small changes.
208 (defcommand list-metadata (metadata-1 &optional metadata-2 search-term)
98aca3cd »
2008-07-15 Add commands.
209 "List all metadata of `metadata-1'.
210 If `metadata-2' & `search-term' are supplied,
211 then list all `metadata-1' in which `metadata-2' has value `search-term'."
212 (send "list" metadata-1 metadata-2 search-term))
213
26c2d20d »
2008-09-14 Small changes.
214 (defcommand search-tracks (type what)
98aca3cd »
2008-07-15 Add commands.
215 "Find tracks in the database with a case sensitive, inexact match."
5b0e9b16 »
2008-09-01 Various changes.
216 (assert (member type +tag-types+))
a0f7b041 »
2008-09-04 Argument checking.
217 (check-args string what)
98aca3cd »
2008-07-15 Add commands.
218 (parse-list (send "search" type what) 'track))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
219
220 (defcommand list-all-info (&optional path)
98aca3cd »
2008-07-15 Add commands.
221 "Lists all information about files in `path' recursively. Default path is /."
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
222 (parse-list (send "listallinfo" path) 'track))
223
224 (defcommand list-all (&optional path)
98aca3cd »
2008-07-15 Add commands.
225 "Lists all files in `path' recursively. Default path is /."
a0f7b041 »
2008-09-04 Argument checking.
226 (check-args (or string null) path)
fff275ea »
2008-09-01 Added: shuffle, list-playlist.
227 (filter-keys (send "listall" path)))
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
228
229 (defcommand list-info (&optional path)
230 "Show contents of directory."
a0f7b041 »
2008-09-04 Argument checking.
231 (check-args (or string null) path)
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
232 (parse-list (send "lsinfo" path) 'track))
233
26c2d20d »
2008-09-14 Small changes.
234 (defcommand count-tracks (scope query)
8dae2cb4 »
2008-08-29 Added argument checking.
235 "Number of songs and their total playtime matching `query'.
98aca3cd »
2008-07-15 Add commands.
236 Return: (number playtime)."
26c2d20d »
2008-09-14 Small changes.
237 (check-args string query)
98aca3cd »
2008-07-15 Add commands.
238 (filter-keys (send "count" scope query)))
239
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
240 (defcommand set-volume (value)
241 "Set the volume to the value between 0-100."
8dae2cb4 »
2008-08-29 Added argument checking.
242 (check-type value (integer 0 100) "an integer in range 0-100")
9f100e00 »
2008-07-15 Move commands into `commands.lisp'.
243 (send "setvol" value))
244
245 (defcommand tag-types ()
246 "Get a list of available metadata types."
247 (filter-keys (send "tagtypes")))
248
249 (defcommand url-handlers ()
250 "Get a list of available URL handlers."
251 (filter-keys (send "urlhandlers")))
Something went wrong with that request. Please try again.