forked from lordpengwin/muzak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery-genres.js
More file actions
58 lines (40 loc) · 1.49 KB
/
query-genres.js
File metadata and controls
58 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* This script queries the SqueezeBox Server for all of the genres and outputs a list of utterances that can be
* used to match them.
*
* Run this with something like (on the Mac)
*
* node query-genres.js | pbcopy
*
* And then paste the result in the utterances of the interaction model
*/
// Integration with the squeeze server
var SqueezeServer = require('squeezenode-lordpengwin');
// Configuration
var config = require('./config');
/**
* Check if the genre is valid from the point of view if being in an utterance
*
* @param genre The genre to test
* @return true if it's valid, false otherwise
*/
function isValidGenre(genre) {
var illegalChars = new RegExp("[0-9\/\\\\&,+]");
return ! illegalChars.test(genre);
}
// Create a SqueezeServer object and connect to the server
var squeezeserver = new SqueezeServer(config.squeezeserverURL, config.squeezeserverPort, config.squeezeServerUsername, config.squeezeServerPassword);
squeezeserver.on('register', function() {
// Get a list of the genres on the server and print it out in the form of an utterance
squeezeserver.getGenres(function callback(reply) {
if (! reply.ok) {
console.log("Failed to get genres from server");
return;
}
// Print out each of the genres
for (var g in reply.result) {
if (isValidGenre(reply.result[g].genre))
console.log("PlayPlaylist play genre {" + reply.result[g].genre + "|Genre}");
}
}, 1000);
});