Allow song randomization when tags are duplicated

This commit is contained in:
Annika Backstrom 2017-04-11 18:58:43 -04:00
parent cc9d85324b
commit 320c4f7aa5
2 changed files with 7 additions and 2 deletions

View File

@ -24,7 +24,7 @@ var html = `
<h1>tag-reader-dummy</h1>
<form method="post" class="pure-form">
<input class="pure-button pure-button-primary" type="submit" name="uid" value="12121212">
OK Then.mp3
OK Then.mp3 / Other.mp3
</form>
<form method="post" class="pure-form">
<input class="pure-button pure-button-primary" type="submit" name="uid" value="BADC0FFEE">

View File

@ -2,6 +2,11 @@
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;
@ -10,7 +15,7 @@ class FileBackend {
find(tag, callback) {
glob(this.config.media_path + '/' + tag + ' - *.mp3', (err, files) => {
if (files.length > 0) {
return callback(files[0]);
return callback(pickRandom(files));
}
callback();
});