Allow song randomization when tags are duplicated
This commit is contained in:
parent
cc9d85324b
commit
320c4f7aa5
@ -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">
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user