Move media player path into config

This commit is contained in:
Annika Backstrom 2017-04-10 23:08:59 -04:00
parent 6ad68b777d
commit cc9d85324b
6 changed files with 25 additions and 19 deletions

4
.gitignore vendored
View File

@ -2,8 +2,4 @@ node_modules
lib lib
.vagrant .vagrant
config.json config.json
npm-debug.log npm-debug.log
media/*
!media/.do_not_delete

View File

@ -3,6 +3,13 @@
"tag_reader": ["./lib/bin/python", "./bin/tag-reader"], "tag_reader": ["./lib/bin/python", "./bin/tag-reader"],
"mpg321": ["/usr/bin/mpg321", "-R", "-"], "mpg321": ["/usr/bin/mpg321", "-R", "-"],
"media_path": "/path/to/media",
"play_throttle": 5000,
"pause_throttle": 2000,
"stop_throttle": 2000,
"unknown_throttle": 2000,
"stop_id": "abcdef1234", "stop_id": "abcdef1234",
"pause_id": "567890abcd" "pause_id": "567890abcd"
} }

View File

@ -1,7 +1,6 @@
"use strict"; "use strict";
const glob = require('glob'); const glob = require('glob');
const basename = require('path').basename;
class FileBackend { class FileBackend {
constructor(config) { constructor(config) {
@ -9,9 +8,9 @@ class FileBackend {
} }
find(tag, callback) { find(tag, callback) {
glob('media/' + tag + ' - *.mp3', (err, files) => { glob(this.config.media_path + '/' + tag + ' - *.mp3', (err, files) => {
if (files.length > 0) { if (files.length > 0) {
return callback(basename(files[0])); return callback(files[0]);
} }
callback(); callback();
}); });

View File

@ -1,3 +1,5 @@
const basename = require('path').basename;
class Tag { class Tag {
constructor(tag) { constructor(tag) {
this.tag = tag; this.tag = tag;
@ -9,15 +11,15 @@ class Tag {
} }
class StopCommand extends Tag { class StopCommand extends Tag {
toString() { toString() {
return "Command: STOP"; return "Command: STOP";
} }
} }
class PauseCommand extends Tag { class PauseCommand extends Tag {
toString() { toString() {
return "Command: PAUSE"; return "Command: PAUSE";
} }
} }
class NotFoundTag extends Tag { class NotFoundTag extends Tag {
@ -33,15 +35,15 @@ class FileTag extends Tag {
} }
toString() { toString() {
return this.path; return basename(this.path);
} }
} }
module.exports = { module.exports = {
StopCommand: StopCommand StopCommand: StopCommand
, PauseCommand: PauseCommand , PauseCommand: PauseCommand
, NotFoundTag: NotFoundTag , NotFoundTag: NotFoundTag
, FileTag: FileTag , FileTag: FileTag
}; };
// vim:ts=2 sw=2 et: // vim:ts=2 sw=2 et:

View File

@ -15,6 +15,8 @@ class MediaPlayer extends ChildProcessEmitter {
constructor(config, logger) { constructor(config, logger) {
super(config.mpg321, logger); super(config.mpg321, logger);
this.config = config;
this.stderrFilters.push(line => { this.stderrFilters.push(line => {
return line.substr(0, 3) == '@F ' return line.substr(0, 3) == '@F '
}); });
@ -50,7 +52,7 @@ class MediaPlayer extends ChildProcessEmitter {
_playFile(tag) { _playFile(tag) {
this.emit('command', tag); this.emit('command', tag);
this.send("LOAD media/" + tag.path); this.send("LOAD " + tag.path);
} }
_unknown(tag) { _unknown(tag) {

View File