The swiss army knife of lossless video/audio editing
fix seg num padding
Mikael Finstad391dce22bd62
diff --git a/src/hooks/useFrameCapture.js b/src/hooks/useFrameCapture.jsindex 16921f9a..b5b20dd0 100644--- a/src/hooks/useFrameCapture.js+++ b/src/hooks/useFrameCapture.js@@ -1,7 +1,8 @@import dataUriToBuffer from 'data-uri-to-buffer';import pMap from 'p-map';-import { getSuffixedOutPath, getOutDir, transferTimestamps, getSuffixedFileName, getOutPath, escapeRegExp, getNumDigits } from '../util';+import { getSuffixedOutPath, getOutDir, transferTimestamps, getSuffixedFileName, getOutPath, escapeRegExp } from '../util';+import { getNumDigits } from '../segments';import { captureFrame as ffmpegCaptureFrame, captureFrames as ffmpegCaptureFrames } from '../ffmpeg';diff --git a/src/segments.js b/src/segments.jsindex f6eeaaf2..b9d04a81 100644--- a/src/segments.js+++ b/src/segments.js@@ -232,3 +232,10 @@ export function playOnlyCurrentSegment({ playbackMode, currentTime, playingSegmereturn {};}++export const getNumDigits = (value) => Math.floor(value > 0 ? Math.log10(value) : 0) + 1;++export function formatSegNum(segIndex, numSegments) {+ const numDigits = getNumDigits(numSegments);+ return `${segIndex + 1}`.padStart(numDigits, '0');+}diff --git a/src/segments.test.js b/src/segments.test.jsindex a905b846..a108c71b 100644--- a/src/segments.test.js+++ b/src/segments.test.js@@ -1,6 +1,6 @@-import { it, expect } from 'vitest';+import { test, it, expect } from 'vitest';-import { convertSegmentsToChapters, partitionIntoOverlappingRanges, getSegApparentStart, getSegApparentEnd } from './segments';+import { convertSegmentsToChapters, partitionIntoOverlappingRanges, getSegApparentStart, getSegApparentEnd, formatSegNum } from './segments';it('converts segments to chapters with gaps', () => {expect(convertSegmentsToChapters([@@ -109,3 +109,8 @@ it('detects overlapping segments, undefined end', () => {[{ start: 1, end: undefined }, { start: 1.5, end: undefined }],]);});++test('formatSegNum', () => {+ expect(formatSegNum(0, 9)).toBe('1');+ expect(formatSegNum(0, 10)).toBe('01');+});diff --git a/src/util.js b/src/util.jsindex 9b99ac0f..41d44464 100644--- a/src/util.js+++ b/src/util.js@@ -300,8 +300,6 @@ export function shuffleArray(arrayIn) {return array;}-export const getNumDigits = (value) => Math.floor(value > 0 ? Math.log10(value) : 0) + 1;-// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escapingexport function escapeRegExp(string) {return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched stringdiff --git a/src/util/outputNameTemplate.js b/src/util/outputNameTemplate.jsindex acb7224f..f9e971e2 100644--- a/src/util/outputNameTemplate.js+++ b/src/util/outputNameTemplate.js@@ -1,9 +1,9 @@import i18n from 'i18next';import lodashTemplate from 'lodash/template';-import { isMac, isWindows, hasDuplicates, filenamify, getOutFileExtension, getNumDigits } from '../util';+import { isMac, isWindows, hasDuplicates, filenamify, getOutFileExtension } from '../util';import isDev from '../isDev';-import { getSegmentTags } from '../segments';+import { getSegmentTags, formatSegNum } from '../segments';const { parse: parsePath, sep: pathSep, join: pathJoin, normalize: pathNormalize } = window.require('path');@@ -85,15 +85,10 @@ function interpolateSegmentFileName({ template, inputFileNameWithoutExt, segSuffreturn compiled(data);}-function formatSegNum(segIndex, segments) {- const numDigits = getNumDigits(segments);- return `${segIndex + 1}`.padStart(numDigits, '0');-}-export function generateOutSegFileNames({ segments, template, forceSafeOutputFileName, formatTimecode, isCustomFormatSelected, fileFormat, filePath, safeOutputFileName, maxLabelLength }) {return segments.map((segment, i) => {const { start, end, name = '' } = segment;- const segNum = formatSegNum(i, segments);+ const segNum = formatSegNum(i, segments.length);// Fields that did not come from the source file's name must be sanitized, because they may contain characters that are not supported by the target operating/file system// however we disable this when the user has chosen to (safeOutputFileName === false)