-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·57 lines (47 loc) · 1.39 KB
/
cli.js
File metadata and controls
executable file
·57 lines (47 loc) · 1.39 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
56
57
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var path = require('path');
var Mopidy = require('mopidy');
var encoder = require('../lib/encoder');
var argv = require('yargs')
.options('initd-config', {
alias: 'i',
boolean: true,
default: false,
description: 'Displays out the related Debian initd script.'
})
.options('base-dir', {
alias: 'd',
default: '/usr/share/tinyfm',
description: 'Base directory to resolve event media filepath from.'
})
.options('start', {
boolean: true,
default: false,
description: 'Starts to media playback to FM broadcasting server.'
})
.strict()
.argv;
if (argv.initdConfig) {
return fs.createReadStream(path.join(__dirname, '..', 'dist', 'init.d', 'mpd2fm'))
.pipe(process.stdout);
}
if (argv.start) {
var mopidy = new Mopidy({
callingConvention: 'by-position-or-by-name',
webSocketUrl: 'ws://' + (process.env.HOST || 'localhost') + ':6680/mopidy/ws/'
});
var broadcast = encoder({ baseDir: argv.baseDir, env: 'test' });
var currentStream;
mopidy.on("event:trackPlaybackStarted", function (event) {
// catch the uri
var filepath = event.tl_track.track.uri.split(":").pop();
console.log("-----------------------------------");
console.log("New song:", filepath);
currentStream = broadcast(filepath);
}, logErrors);
}
function logErrors(err){
console.error(err);
}