From 320c4f7aa51269e807902c0aa7c8f7eba1e4ec50 Mon Sep 17 00:00:00 2001 From: Annika Backstrom Date: Tue, 11 Apr 2017 18:58:43 -0400 Subject: [PATCH] Allow song randomization when tags are duplicated --- bin/tag-reader-dummy | 2 +- jukebox/library/file-backend.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/tag-reader-dummy b/bin/tag-reader-dummy index 9727933..9eaed9f 100755 --- a/bin/tag-reader-dummy +++ b/bin/tag-reader-dummy @@ -24,7 +24,7 @@ var html = `

tag-reader-dummy

- OK Then.mp3 + OK Then.mp3 / Other.mp3
diff --git a/jukebox/library/file-backend.js b/jukebox/library/file-backend.js index bcf5459..6226a2e 100644 --- a/jukebox/library/file-backend.js +++ b/jukebox/library/file-backend.js @@ -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(); });