-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (47 loc) · 1.11 KB
/
index.js
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
var express = require('express');
var app = express();
var iTunes = require('local-itunes');
app.get('/status', function(req, res){
console.log("[GET] /status");
iTunes.playerState(function(error, state){
res.json({ state: state });
});
});
app.get('/play', function(req, res){
console.log("[GET] /play");
iTunes.play();
iTunes.playerState(function(error, state){
res.json({ state: state });
});
});
app.get('/pause', function(req, res){
console.log("[GET] /pause");
iTunes.pause();
iTunes.playerState(function(error, state){
res.json({ state: state });
});
});
app.get('/playpause', function(req, res){
console.log("[GET] /playpause");
iTunes.playpause();
iTunes.playerState(function(error, state){
res.json({ state: state });
});
});
app.get('/previous', function(req, res){
console.log("[GET] /previous");
iTunes.previous();
res.end();
});
app.get('/next', function(req, res){
console.log("[GET] /next");
iTunes.next();
res.end();
});
module.exports = {
start: function(port) {
var server = app.listen(port);
console.log('iTunes Control API started on port ' + port);
return server;
}
};