2017-04-09 20:57:32 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const EventEmitter = require('events').EventEmitter;
|
2017-04-10 02:05:52 +00:00
|
|
|
const tags = require('./tags');
|
2017-04-09 20:57:32 +00:00
|
|
|
|
|
|
|
class Library extends EventEmitter {
|
|
|
|
constructor(config, backend) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.config = config;
|
|
|
|
this.backend = backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
find(tag) {
|
2017-04-10 02:05:52 +00:00
|
|
|
if (tag === this.config.stop_id) {
|
2017-04-10 02:40:23 +00:00
|
|
|
this.emit('action', new tags.StopCommand(tag));
|
|
|
|
return;
|
2017-04-10 02:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tag === this.config.pause_id) {
|
2017-04-10 02:40:23 +00:00
|
|
|
this.emit('action', new tags.PauseCommand(tag));
|
|
|
|
return;
|
2017-04-10 02:05:52 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 20:57:32 +00:00
|
|
|
this.backend.find(tag, path => {
|
|
|
|
if (!path) {
|
2017-04-10 02:05:52 +00:00
|
|
|
this.emit('action', new tags.NotFoundTag(tag));
|
2017-04-09 20:57:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-10 02:05:52 +00:00
|
|
|
this.emit('action', new tags.FileTag(tag, path));
|
2017-04-09 20:57:32 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.Library = Library;
|
|
|
|
|
|
|
|
// vim:set ts=2 sw=2 et:
|