diff --git a/jukebox/library/index.js b/jukebox/library/index.js index 7c6dfd9..5d4ad1a 100644 --- a/jukebox/library/index.js +++ b/jukebox/library/index.js @@ -22,13 +22,13 @@ class Library extends EventEmitter { return; } - this.backend.find(tag, path => { - if (!path) { + this.backend.find(tag, track => { + if (!track) { this.emit('action', new tags.NotFoundTag(tag)); return; } - this.emit('action', new tags.FileTag(tag, path)); + this.emit('action', new tags.FileTag(tag, track)); }); } } diff --git a/jukebox/library/sqlite-backend.js b/jukebox/library/sqlite-backend.js index 9b17ed1..31603f5 100644 --- a/jukebox/library/sqlite-backend.js +++ b/jukebox/library/sqlite-backend.js @@ -1,5 +1,7 @@ "use strict"; +const Track = require('./track'); + class SqliteBackend { constructor(config, db) { this.config = config; @@ -7,11 +9,11 @@ class SqliteBackend { } find(tag, callback) { - this.db.get("SELECT uuid FROM tags WHERE tag = ? AND _ROWID_ >= (abs(random()) % (SELECT max(_ROWID_) FROM tags)) LIMIT 1", tag, (err, row) => { + this.db.get("SELECT uuid, tag, label FROM tags WHERE tag = ? AND _ROWID_ >= (abs(random()) % (SELECT max(_ROWID_) FROM tags)) LIMIT 1", tag, (err, row) => { if (typeof row === 'undefined') { return callback(); } - callback(row['uuid']); + callback(new Track(row['tag'], row['uuid'], row['label'])); }); } } diff --git a/jukebox/library/tags.js b/jukebox/library/tags.js index 767fddf..6c503ca 100644 --- a/jukebox/library/tags.js +++ b/jukebox/library/tags.js @@ -29,13 +29,13 @@ class NotFoundTag extends Tag { } class FileTag extends Tag { - constructor(tag, path) { + constructor(tag, track) { super(tag); - this.path = path; + this.track = track; } toString() { - return basename(this.path); + return this.track.label; } } diff --git a/jukebox/library/track.js b/jukebox/library/track.js new file mode 100644 index 0000000..8f850dc --- /dev/null +++ b/jukebox/library/track.js @@ -0,0 +1,11 @@ +"use strict"; + +class Track { + constructor(tag, uuid, label) { + this.tag = tag; + this.uuid = uuid; + this.label = label; + } +} + +module.exports = Track; diff --git a/jukebox/media-player.js b/jukebox/media-player.js index d5c15ca..706627b 100644 --- a/jukebox/media-player.js +++ b/jukebox/media-player.js @@ -52,7 +52,7 @@ class MediaPlayer extends ChildProcessEmitter { _playFile(tag) { this.emit('command', tag); - this.send("LOAD " + tag.path); + this.send("LOAD " + tag.track.uuid); } _unknown(tag) {