pi-rfid-jukebox/jukebox/library/file-backend.js

30 lines
539 B
JavaScript
Raw Normal View History

"use strict";
const glob = require('glob');
function pickRandom(arr) {
var index = Math.floor(Math.random() * arr.length);
return arr[index];
}
class FileBackend {
constructor(config) {
this.config = config;
}
find(tag, callback) {
2017-04-11 23:12:53 +00:00
glob(this.config.media_path + '/**/' + tag + ' - *.mp3', (err, files) => {
if (files.length > 0) {
return callback(pickRandom(files));
}
callback();
});
}
}
module.exports = function(config) {
return new FileBackend(config);
};
// vim:ts=2 sw=2 et: