diff options
Diffstat (limited to 'backend.js')
-rw-r--r-- | backend.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/backend.js b/backend.js index 23a9309..b8071d1 100644 --- a/backend.js +++ b/backend.js @@ -9,6 +9,7 @@ const { getPlayer } = require('./players') const RecordStore = require('./record-store') const { + getTimeStringsFromSec, shuffleArray, throttlePromise } = require('./general-util') @@ -518,6 +519,31 @@ class Backend extends EventEmitter { } } + getDuration(item) { + let noticedMissingMetadata = false + + const durationFn = (acc, track) => { + const metadata = this.getMetadataFor(track) + if (!metadata) noticedMissingMetadata = true + return acc + (metadata && metadata.duration) || 0 + } + + let items + if (isGroup(item)) { + items = flattenGrouplike(item).items + } else { + items = [item] + } + + const seconds = items.reduce(durationFn, 0) + + let { duration: string } = getTimeStringsFromSec(0, seconds) + const approxSymbol = noticedMissingMetadata ? '+' : '' + string += approxSymbol + + return {seconds, string, noticedMissingMetadata, approxSymbol} + } + async download(item) { if (isGroup(item)) { // TODO: Download all children (recursively), show a confirmation prompt |