configure: add two mysql-related command line options
[paraslash.git] / README.mysql
1 README.mysql
2 ============
3
4 This file describes how to use the mysql audio file selector which
5 comes with the paraslash package.
6
7 It assumes you have already installed mysql and paraslash as described
8 in INSTALL, so read README and INSTALL before proceeding.
9
10 First of all, make sure that
11
12 - mysqld is running
13
14 - para_server is running and compiled with mysql support
15 (type "para_client si" to find out)
16
17 - the user who runs para_client has the paraslash DB_WRITE
18 and DB_READ permissions set in server.users
19
20 - the user who runs para_server has create privileges on the
21 mysql server.
22
23 Remember: If something doesn't work as expected, look at the server
24 log file and/or increase output verbosity by using the -l switch for
25 server and client.
26
27
28 Specify mysql data (port, passwd,...)
29 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30
31 Type
32
33 para_server -h
34
35 and look at the mysql options. You may either specify these options
36 in ~/.paraslash/server.conf or directly at the command line (not
37 recommended for passwd option). Don't forget to do
38
39 chmod 600 ~/.paraslash/server.conf
40
41 as this file contains the mysql passwd. To make these changes take
42 effect you'll need to do
43
44 para_client hup
45
46 Or, restart the server.
47
48 Switch to the mysql audio file selector
49 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
51 The command
52
53 para_client chs
54
55 prints the name of the current selector. Try
56
57 para_client chs mysql
58
59 to switch to the mysql selector. If this doesn't work, it means that
60 some required config options were not specified (check the log for
61 more info) or that para_server was built without mysql support. Type
62
63 para_client si
64
65 to find out. If mysql is not mentioned as a supported selector,
66 you'll have to recompile. If configure does not detect your mysql
67 installation, use the --enable-mysql-headers and --enable-mysql-libs
68 options to specify the mysql path explicitly . Example:
69
70 ./configure --enable-mysql-headers=/Library/MySQL/include \
71 --enable-mysql-libs=/Library/MySQL/lib/mysql
72
73
74 Create a new database
75 ~~~~~~~~~~~~~~~~~~~~~
76
77 Once the mysql selector is activated, create the database:
78
79 para_client cdb
80 para_client chs mysql
81
82 The second command forces para_server to re-init the mysql selector.
83 Check the log. There should not be any warnings or errors.
84
85
86 Fill your database with content
87 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88
89 para_client upd
90
91 If this command fails, it most likely means the audio file directory
92 (given in the server configuration file) does not exist, is empty,
93 not readable, or contains different files with identical basenames. Fix
94 this problem before proceeding.
95
96 The command
97
98 para_client ls
99
100 prints the list of all files known by the mysql selector. If the list
101 is empty, double check the mysql_audio_file_dir option.
102
103
104 Create a stream which selects all songs
105 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106
107 To keep it simple, let's only define the stream "all_songs". See below for
108 advanced stream usage.
109
110 para_client stradd all_songs < /dev/null
111 para_client sl 10 all_songs
112
113 The latter command should show you ten filenames.
114
115
116 Change to the all_songs stream
117 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118
119 para_client cs all_songs
120
121 You should now be able to start streaming with
122
123 para_client play
124
125
126 Attribute usage
127 ~~~~~~~~~~~~~~~
128
129 An attribute is simply a bit which can be set for each audio file
130 individually. You may have as many attributes as you like. A new
131 attribute "test" is created by
132
133 para_client na test
134
135 and
136 para_client laa
137
138 lists all available attributes. You can set the "test" attribute for
139 the current audio file by executing
140
141 para_client sa test+
142
143 or for any particular audio file by
144
145 para_client sa test+ filename
146
147 Unset the attribute "test" for the current audio file with
148
149 para_client sa test-
150
151 and drop the test attribute entirely from the database with
152
153 para_client da test
154
155 Stream usage
156 ~~~~~~~~~~~~
157
158 A stream is a pair of expressions in terms of attributes and other data
159 contained in the database. The first, boolian, expression determines
160 the set of audio files which are admissible in this stream. The second,
161 integer, expression determines the order in which admissible files
162 are going to be fed to the audio file sender(s).
163
164 To create a new stream called "my_stream", put arbitrary many (including
165 none) accept or deny lines and one or zero score lines into some
166 temporary file, say tmpfile. An accept/deny/score line consists of
167 an identifier ("accept:", "deny:", or "score:"), followed by an
168 expression. The command
169
170 para_client stradd my_stream < tmpfile
171
172 adds the stream "my_stream" to the table of streams.
173
174 If the stream definition is really short, you may also just pipe it to
175 the client rather than using temporary files. Like this:
176
177 echo "$MYSTREAMDEF" | para_client stradd my_stream
178
179
180 Example:
181
182 Assume you already have an attribute "test" and you'd like to
183 to restrict audio streaming to those files having the "test"
184 attribute set. Define a new stream "only_test" by
185
186 echo 'accept: IS_SET(test)' | para_client stradd only_test
187
188 Then, after switching to the "only_test" stream with
189
190 para_client cs only_test
191
192 only the desired files are going to be streamed.
193
194 There is no need to keep the temporary files containing the stream
195 definition since you can always use the strq command to get it back:
196
197 para_client strq only_test
198
199 The accept/deny expressions are used to find out which songs are
200 permitted. The following four cases are all possible and valid:
201
202 o Neither accept nor deny lines: This selects all songs.
203
204 o Only accept lines: Songs that match at least one accept
205 expression are accepted, all others are denied:
206
207 accept_expr1 or accept_expr2 or ...
208
209 o Only deny lines: Songs that match at least one deny expression are
210 denied, all others are accepted:
211
212 not (deny_expr1 or deny_expr2 ...)
213
214 o Both accept and deny lines: A song is accepted if it matches
215 at least one accept expression, but no deny expression, i.e.
216
217 (accept_expr1 or accept_expr2 or ..) and not
218 (deny_expr1 or deny_expr2 ..)
219
220 The command
221
222 para_client streams
223
224 lists all available streams and
225
226 para_client strdel streamname
227
228 removes the stream "streamname".
229
230 There are more sophisticated ways to define a stream than just using
231 one IS_SET() macro as in the example above. Of course, IS_SET(foo)
232 is true for a given audio file if and only if it has the attribute
233 "foo" set. Here are some more macros you can use:
234
235 o IS_N_SET(attr): True if attribute attr is not set
236
237 o NAME_LIKE(string): True if basename is like (in the sense
238 of mysql) "string"
239
240 o LASTPLAYED(): Expands to number of minutes that are gone
241 since this audio file has been played (by paraslash).
242
243 o NUMPLAYED(): Expands to number of times, the file has
244 been played.
245
246 o PICID(): Expands to the number of the picture which is
247 associated with this song.
248
249 To give a real-life example, suppose you have already added the
250 attributes "pop", "rock" with the "na" command. Assume also that you
251 have set these attributes for some or all of your songs having the
252 corresponding properties.
253
254 If you like to be waked up in the morning by poprock songs, but you
255 have some strange feeling telling you that just a few seconds of
256 Madonna's voice will be enough to mess up your whole day, just write
257 the lines
258
259 accept: IS_SET(pop) and IS_SET(rock)
260 deny: NAME_LIKE(%Madonna%)
261
262 to some temporary file "tmp" and do
263
264 para_client stradd wake < tmp
265
266 You can then switch to the new stream with
267
268 para_client cs wake
269
270 or you can let cron do this for you on a daily basis..
271
272 Accept/deny lines affect only the set of admissible audio files,
273 but not the order in which these are streamed. That's where the score
274 expression comes into play.
275
276 Scoring
277 ~~~~~~~
278 You may put a single score line anywhere in the stream definition. If
279 omitted, the default scoring rule specified in the configuration file
280 applies. If there is no default scoring rule in the config file either,
281 the compiled in default is going to be used (see para_server -h).
282
283 Simple examples of scoring rules (either specified in a stream
284 definition or as the default scoring rule in the config file) include:
285
286 LASTPLAYED()/1440
287
288 This means that the score of an audio file is just the number of days
289 that went by since it has been played the last time (one day is 1440
290 minutes). In other words, the mysql selector choses that admissible
291 file which wasn't played for the longest time.
292
293 However, one disadvantage of this scoring sheme is that new files,
294 once played, are going to be deferred for a possibly very long period
295 depending on the size of your collection of (admissible) files. Hence
296 the following scoring rule comes into mind:
297
298 score: -NUMPLAYED()
299
300 since this gives newer files, i.e. files to which you haven't listen to
301 that often, a higher score than older songs you already know by heart.
302
303 You can also use a combination of these two methods:
304
305 score: LASTPLAYED()/1440 - 10 * NUMPLAYED()
306
307 which subtracts 10 score points for each time paraslash has played
308 this file.
309
310 Another useful feature for scoring is due to the fact that
311 "true" expands to one and "false" to zero. So you can also use the
312 IS_SET/IS_N_SET/NAME_LIKE macros in a score line to give your favorite
313 band "bar" some extra points:
314
315 score: 40 * IS_SET(foo) + 20 * NAME_LIKE(%bar%) + LASTPLAYED()/1440
316
317
318 Pictures
319 ~~~~~~~~
320
321 The mysql selector can also magage images that, when associated
322 with one or more audio files, can be displayed by para_sdl_gui and
323 para_krell. It is also possible to just retrieve the current image via
324
325 para_client pic > filename
326
327 in order to feed it to your favorite tool. Try
328
329 para_client help | grep ^pic
330
331 and read the online help of the shown commands for more information.