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
.vagrant
config.json
npm-debug.log
media/*
!media/.do_not_delete

View File

@ -3,6 +3,13 @@
"tag_reader": ["./lib/bin/python", "./bin/tag-reader"],
"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",
"pause_id": "567890abcd"
}

View File

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

View File

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

View File

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

View File