From 39732bd31e13c9a785eac1fc724bc9fc768be2ab Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 14 Aug 2021 00:44:47 -0300 Subject: show timestamp hours column whenever appropriate --- combine-album.js | 8 +++++--- general-util.js | 17 +++++++++++++++-- ui.js | 12 ++++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/combine-album.js b/combine-album.js index 9fd9cf0..946c4c1 100644 --- a/combine-album.js +++ b/combine-album.js @@ -3,7 +3,7 @@ // too lazy to use import syntax :) const { readdir, readFile, stat, writeFile } = require('fs/promises') const { spawn } = require('child_process') -const { promisifyProcess, parseOptions } = require('./general-util') +const { getTimeStringsFromSec, parseOptions, promisifyProcess } = require('./general-util') const { musicExtensions } = require('./crawlers') const path = require('path') const shellescape = require('shell-escape') @@ -164,13 +164,15 @@ async function main() { return 1 } + const duration = tsData[tsData.length - 1].timestampEnd + let tsText switch (opts.format) { case 'json': tsText = JSON.stringify(tsData) + '\n' break case 'txt': - tsText = tsData.map(t => `${t.timestamp} ${t.comment}`).join('\n') + '\n' + tsText = tsData.map(t => `${getTimeStringsFromSec(t.timestamp, duration, true).timeDone} ${t.comment}`).join('\n') + '\n' break } @@ -197,7 +199,7 @@ async function main() { const concatListPath = opts['concat-list'] || `/tmp/combine-album-concat.txt` try { - await writeFile(concatListPath, files.map(file => `file ${path.resolve(shellescape([file]))}`).join('\n') + '\n') + await writeFile(concatListPath, files.map(file => `file ${shellescape([path.resolve(file)])}`).join('\n') + '\n') console.log(`Generated ffmpeg concat list at ${concatListPath}`) console.log(`# To concat:`) console.log(`ffmpeg -f concat -safe 0 -i ${shellescape([concatListPath])} -c copy ${shellescape([concatOutput])}`) diff --git a/general-util.js b/general-util.js index f63ae21..aba1541 100644 --- a/general-util.js +++ b/general-util.js @@ -149,7 +149,7 @@ module.exports.getSecFromTimestamp = function(timestamp) { } } -module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal) { +module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal, fraction = false) { const percentVal = (100 / lenSecTotal) * curSecTotal const percentDone = ( (Math.trunc(percentVal * 100) / 100).toFixed(2) + '%' @@ -159,29 +159,36 @@ module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal) { let leftHour = Math.floor(leftSecTotal / 3600) let leftMin = Math.floor((leftSecTotal - leftHour * 3600) / 60) let leftSec = Math.floor(leftSecTotal - leftHour * 3600 - leftMin * 60) + let leftFrac = lenSecTotal % 1 // Yeah, yeah, duplicate math. let curHour = Math.floor(curSecTotal / 3600) let curMin = Math.floor((curSecTotal - curHour * 3600) / 60) let curSec = Math.floor(curSecTotal - curHour * 3600 - curMin * 60) + let curFrac = curSecTotal % 1 // Wee! let lenHour = Math.floor(lenSecTotal / 3600) let lenMin = Math.floor((lenSecTotal - lenHour * 3600) / 60) let lenSec = Math.floor(lenSecTotal - lenHour * 3600 - lenMin * 60) + let lenFrac = lenSecTotal % 1 const pad = val => val.toString().padStart(2, '0') + const padFrac = val => Math.floor(val * 1000).toString().padEnd(3, '0') curMin = pad(curMin) curSec = pad(curSec) lenMin = pad(lenMin) lenSec = pad(lenSec) leftMin = pad(leftMin) leftSec = pad(leftSec) + curFrac = padFrac(curFrac) + lenFrac = padFrac(lenFrac) + leftFrac = padFrac(leftFrac) // We don't want to display hour counters if the total length is less // than an hour. let timeDone, timeLeft, duration - if (parseInt(lenHour) > 0) { + if (parseInt(lenHour) > 0 || parseInt(curHour) > 0) { timeDone = `${curHour}:${curMin}:${curSec}` timeLeft = `${leftHour}:${leftMin}:${leftSec}` duration = `${lenHour}:${lenMin}:${lenSec}` @@ -191,6 +198,12 @@ module.exports.getTimeStringsFromSec = function(curSecTotal, lenSecTotal) { duration = `${lenMin}:${lenSec}` } + if (fraction) { + timeDone += '.' + curFrac + timeLeft += '.' + leftFrac + duration += '.' + lenFrac + } + return {percentDone, timeDone, timeLeft, duration, curSecTotal, lenSecTotal} } diff --git a/ui.js b/ui.js index 2da7e02..d6452d9 100644 --- a/ui.js +++ b/ui.js @@ -2557,7 +2557,7 @@ class GrouplikeListingElement extends Form { // Generate some items! Just go over the data list and generate one for // each timestamp. const tsElements = timestampData.map(ts => { - const el = new TimestampGrouplikeItemElement(item, ts, this.app) + const el = new TimestampGrouplikeItemElement(item, ts, timestampData, this.app) el.on('pressed', () => this.emit('timestamp', item, ts.timestamp)) if (this.grouplike.isTheQueue) { el.hideMetadata = true @@ -3752,20 +3752,24 @@ class InteractiveGrouplikeItemElement extends BasicGrouplikeItemElement { } class TimestampGrouplikeItemElement extends BasicGrouplikeItemElement { - constructor(item, timestampData, app) { + constructor(item, timestampData, tsDataArray, app) { super('') this.app = app this.data = timestampData + this.tsData = tsDataArray this.item = item this.hideMetadata = false } drawTo(writable) { - const { data } = this + const { data, tsData } = this const metadata = this.app.backend.getMetadataFor(this.item) - const duration = (metadata && metadata.duration) || 0 + const last = tsData[tsData.length - 1] + const duration = ((metadata && metadata.duration) + || last.timestampEnd !== Infinity && last.timestampEnd + || last.timestamp) const strings = getTimeStringsFromSec(data.timestamp, duration) const stringsEnd = getTimeStringsFromSec(data.timestampEnd, duration) -- cgit 1.3.0-6-gf8a5