The swiss army knife of lossless video/audio editing
fix test
Mikael Finstade777aba0d14b
diff --git a/src/App.jsx b/src/App.jsxindex 491c9dac..65930af5 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -66,7 +66,8 @@ import { adjustRate } from './util/rate-calculator';import { askForOutDir, askForImportChapters, createNumSegments, createFixedDurationSegments, promptTimeOffset, askForHtml5ifySpeed, askForFileOpenAction, confirmExtractAllStreamsDialog, cleanupFilesDialog, showDiskFull, showCutFailedDialog, labelSegmentDialog, openYouTubeChaptersDialog, openAbout, showEditableJsonDialog } from './dialogs';import { openSendReportDialog } from './reporting';import { fallbackLng } from './i18n';-import { createSegment, getCleanCutSegments, getSegApparentStart, findSegmentsAtCursor, sortSegments, invertSegments, getSegmentTags, getOutSegError as getOutSegErrorRaw } from './segments';+import { createSegment, getCleanCutSegments, getSegApparentStart, findSegmentsAtCursor, sortSegments, invertSegments, getSegmentTags } from './segments';+import { getOutSegError as getOutSegErrorRaw } from './util/outputNameTemplate';const isDev = window.require('electron-is-dev');diff --git a/src/segments.js b/src/segments.jsindex 46b0a295..44df0842 100644--- a/src/segments.js+++ b/src/segments.js@@ -1,11 +1,5 @@import { v4 as uuidv4 } from 'uuid';import sortBy from 'lodash/sortBy';-import i18n from 'i18next';--import { isMac, isWindows, hasDuplicates } from './util';--const { sep: pathSep, join: pathJoin, normalize: pathNormalize } = window.require('path');-const isDev = window.require('electron-is-dev');export const createSegment = ({ start, end, name, tags, segIndex } = {}) => ({start,@@ -86,45 +80,3 @@ export function invertSegments(sortedCutSegments, duration) {// https://github.com/mifi/lossless-cut/issues/909return ret.filter(({ start, end }) => end == null || start == null || end > start);}--export function getOutSegError({ fileNames, filePath, outputDir }) {- if (hasDuplicates(fileNames)) return i18n.t('Template results in duplicate file names');-- let error;-- // eslint-disable-next-line no-restricted-syntax- for (const fileName of fileNames) {- if (!filePath) {- error = 'No file path';- break;- }-- const invalidChars = [pathSep];-- // Colon is invalid on windows https://github.com/mifi/lossless-cut/issues/631 and on MacOS, but not Linux https://github.com/mifi/lossless-cut/issues/830- if (isMac || isWindows) invalidChars.push(':');-- const outPath = pathNormalize(pathJoin(outputDir, fileName));- const sameAsInputPath = outPath === pathNormalize(filePath);- const windowsMaxPathLength = 259;- const shouldCheckPathLength = isWindows || isDev;-- if (fileName.length === 0) {- error = i18n.t('At least one resulting file name has no length');- break;- }- if (invalidChars.some((c) => fileName.includes(c))) {- error = i18n.t('At least one resulting file name contains invalid characters');- break;- }- if (sameAsInputPath) {- error = i18n.t('At least one resulting file name is the same as the input path');- break;- }- if (shouldCheckPathLength && outPath.length >= windowsMaxPathLength) {- error = i18n.t('At least one resulting file will have a too long path');- break;- }- }- return error;-}diff --git a/src/util/outputNameTemplate.js b/src/util/outputNameTemplate.jsnew file mode 100644index 00000000..a8bf3838--- /dev/null+++ b/src/util/outputNameTemplate.js@@ -0,0 +1,49 @@+import i18n from 'i18next';++import { isMac, isWindows, hasDuplicates } from '../util';++const { sep: pathSep, join: pathJoin, normalize: pathNormalize } = window.require('path');+const isDev = window.require('electron-is-dev');++// eslint-disable-next-line import/prefer-default-export+export function getOutSegError({ fileNames, filePath, outputDir }) {+ if (hasDuplicates(fileNames)) return i18n.t('Template results in duplicate file names');++ let error;++ // eslint-disable-next-line no-restricted-syntax+ for (const fileName of fileNames) {+ if (!filePath) {+ error = 'No file path';+ break;+ }++ const invalidChars = [pathSep];++ // Colon is invalid on windows https://github.com/mifi/lossless-cut/issues/631 and on MacOS, but not Linux https://github.com/mifi/lossless-cut/issues/830+ if (isMac || isWindows) invalidChars.push(':');++ const outPath = pathNormalize(pathJoin(outputDir, fileName));+ const sameAsInputPath = outPath === pathNormalize(filePath);+ const windowsMaxPathLength = 259;+ const shouldCheckPathLength = isWindows || isDev;++ if (fileName.length === 0) {+ error = i18n.t('At least one resulting file name has no length');+ break;+ }+ if (invalidChars.some((c) => fileName.includes(c))) {+ error = i18n.t('At least one resulting file name contains invalid characters');+ break;+ }+ if (sameAsInputPath) {+ error = i18n.t('At least one resulting file name is the same as the input path');+ break;+ }+ if (shouldCheckPathLength && outPath.length >= windowsMaxPathLength) {+ error = i18n.t('At least one resulting file will have a too long path');+ break;+ }+ }+ return error;+}