zero pad SEG_NUM #1446

pull/1441/head
Mikael Finstad 4 years ago
parent eccdf691ac
commit f5ea3daecb
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -65,7 +65,7 @@ import {
checkDirWriteAccess, dirExists, isMasBuild, isStoreBuild, dragPreventer,
filenamify, getOutFileExtension, generateSegFileName, defaultOutSegTemplate,
havePermissionToReadFile, resolvePathIfNeeded, getPathReadAccessError, html5ifiedPrefix, html5dummySuffix, findExistingHtml5FriendlyFile,
deleteFiles, isOutOfSpaceError, shuffleArray,
deleteFiles, isOutOfSpaceError, shuffleArray, getNumDigits,
} from './util';
import { formatDuration } from './util/duration';
import { adjustRate } from './util/rate-calculator';
@ -1235,13 +1235,14 @@ const App = memo(() => {
const { start, end, name = '' } = segment;
const cutFromStr = formatTimecode({ seconds: start, fileNameFriendly: true });
const cutToStr = formatTimecode({ seconds: end, fileNameFriendly: true });
const segNum = i + 1;
const numDigits = getNumDigits(segments.length);
const segNum = `${i + 1}`.padStart(numDigits, '0');
const filenamifyOrNot = (fileName) => (safeOutputFileName || forceSafeOutputFileName ? filenamify(fileName) : fileName).substr(0, maxLabelLength);
// https://github.com/mifi/lossless-cut/issues/583
let segSuffix = '';
if (name) segSuffix = `-${filenamifyOrNot(name)}`;
// https://github.com/mifi/lossless-cut/issues/583
else if (segments.length > 1) segSuffix = `-seg${segNum}`;
const ext = getOutFileExtension({ isCustomFormatSelected, outFormat: fileFormat, filePath });

@ -1,7 +1,7 @@
import dataUriToBuffer from 'data-uri-to-buffer';
import pMap from 'p-map';
import { getSuffixedOutPath, getOutDir, transferTimestamps, getSuffixedFileName, getOutPath, escapeRegExp } from '../util';
import { getSuffixedOutPath, getOutDir, transferTimestamps, getSuffixedFileName, getOutPath, escapeRegExp, getNumDigits } from '../util';
import { captureFrame as ffmpegCaptureFrame, captureFrames as ffmpegCaptureFrames } from '../ffmpeg';
@ -27,7 +27,7 @@ export default ({ formatTimecode }) => {
const getSuffix = (prefix) => `${prefix}.${captureFormat}`;
if (!outputTimestamps) {
const numDigits = Math.floor(Math.log10(estimatedMaxNumFiles)) + 1;
const numDigits = getNumDigits(estimatedMaxNumFiles);
const nameTemplateSuffix = getSuffix(`%0${numDigits}d`);
const nameSuffix = getSuffix(`${'1'.padStart(numDigits, '0')}`); // mimic ffmpeg output
const outPathTemplate = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: nameTemplateSuffix });

@ -352,6 +352,8 @@ 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#escaping
export function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string

Loading…
Cancel
Save