-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
60 lines (49 loc) · 1.67 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
55
56
57
58
59
60
'use strict';
process.title = 'npr-one';
if(process.platform != 'linux' && process.platform != 'darwin') {
console.error('Your platform is not currently supported');
process.exit(1);
}
const NPR = require('npr-api'),
chalk = require('chalk'),
auth = require('./lib/auth'),
fs = require('fs'),
path = require('path'),
config = path.join(process.env['HOME'], '.npr-one'),
dotenv = require('dotenv').load({silent: true, path: config}),
Player = require('./lib/player'),
Story = require('./lib/story'),
UI = require('./lib/ui');
const logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8');
const npr = new NPR(),
story = new Story(npr),
player = new Player();
console.log('connecting to npr one...');
// silence swagger log output
process.env.NODE_ENV = 'test';
npr.one
.init()
.then(auth.getToken.bind(auth, npr))
.then((token) => {
process.stdout.write('\x1B[2J');
process.stdout.write('\x1B[0f');
console.log(logo);
return npr.one.setAccessToken(token);
})
.then(story.getRecommendations.bind(story))
.then(player.load.bind(player))
.then(() => {
const ui = new UI({
touchThreshold: process.env.MPR121_TOUCH,
releaseThreshold: process.env.MPR121_RELEASE
});
ui.on('skip', player.skip.bind(player));
ui.on('pause', player.pause.bind(player));
ui.on('rewind', player.rewind.bind(player));
ui.on('interesting', player.interesting.bind(player));
ui.on('volumeup', player.increaseVolume.bind(player));
ui.on('volumedown', player.decreaseVolume.bind(player));
})
.catch(function(err) {
console.error(err, err.stack);
});