The swiss army knife of lossless video/audio editing
implement "select segments by label"
Mikael Finstad86701ba0a270
diff --git a/src/App.jsx b/src/App.jsxindex e9528def..3fc6a322 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -69,7 +69,7 @@ import {} from './util';import { formatDuration } from './util/duration';import { adjustRate } from './util/rate-calculator';-import { askForOutDir, askForInputDir, askForImportChapters, createNumSegments as createNumSegmentsDialog, createFixedDurationSegments as createFixedDurationSegmentsDialog, promptTimeOffset, askForHtml5ifySpeed, askForFileOpenAction, confirmExtractAllStreamsDialog, showCleanupFilesDialog, showDiskFull, showCutFailedDialog, labelSegmentDialog, openYouTubeChaptersDialog, openAbout, showEditableJsonDialog, askForShiftSegments } from './dialogs';+import { askForOutDir, askForInputDir, askForImportChapters, createNumSegments as createNumSegmentsDialog, createFixedDurationSegments as createFixedDurationSegmentsDialog, promptTimeOffset, askForHtml5ifySpeed, askForFileOpenAction, confirmExtractAllStreamsDialog, showCleanupFilesDialog, showDiskFull, showCutFailedDialog, labelSegmentDialog, openYouTubeChaptersDialog, openAbout, showEditableJsonDialog, askForShiftSegments, selectSegmentsByLabelDialog } from './dialogs';import { openSendReportDialog } from './reporting';import { fallbackLng } from './i18n';import { createSegment, getCleanCutSegments, getSegApparentStart, findSegmentsAtCursor, sortSegments, invertSegments, getSegmentTags, convertSegmentsToChapters, hasAnySegmentOverlap } from './segments';@@ -421,6 +421,19 @@ const App = memo(() => {if (value != null) updateSegAtIndex(index, { name: value });}, [cutSegments, updateSegAtIndex, maxLabelLength]);+ const onSelectSegmentsByLabel = useCallback(async () => {+ const { name } = currentCutSeg;+ const value = await selectSegmentsByLabelDialog(name);+ if (value == null) return;+ const segmentsToEnable = cutSegments.filter((seg) => (seg.name || '') === value);+ if (segmentsToEnable.length === 0 || segmentsToEnable.length === cutSegments.length) return; // no point+ setDeselectedSegmentIds((existing) => {+ const ret = { ...existing };+ segmentsToEnable.forEach(({ segId }) => { ret[segId] = false; });+ return ret;+ });+ }, [currentCutSeg, cutSegments]);+const onViewSegmentTagsPress = useCallback(async (index) => {const segment = cutSegments[index];function inputValidator(jsonStr) {@@ -2314,6 +2327,7 @@ const App = memo(() => {jumpSegStart={jumpSegStart}jumpSegEnd={jumpSegEnd}onViewSegmentTagsPress={onViewSegmentTagsPress}+ onSelectSegmentsByLabel={onSelectSegmentsByLabel}/>)}</AnimatePresence>diff --git a/src/SegmentList.jsx b/src/SegmentList.jsxindex d7eb2c7b..c8919ee6 100644--- a/src/SegmentList.jsx+++ b/src/SegmentList.jsx@@ -21,7 +21,7 @@ const buttonBaseStyle = {const neutralButtonColor = 'rgba(255, 255, 255, 0.2)';-const Segment = memo(({ seg, index, currentSegIndex, formatTimecode, getFrameCount, updateOrder, invertCutSegments, onClick, onRemovePress, onReorderPress, onLabelPress, enabled, onSelectSingleSegment, onToggleSegmentSelected, onDeselectAllSegments, onSelectAllSegments, jumpSegStart, jumpSegEnd, addCutSegment, onViewSegmentTagsPress }) => {+const Segment = memo(({ seg, index, currentSegIndex, formatTimecode, getFrameCount, updateOrder, invertCutSegments, onClick, onRemovePress, onReorderPress, onLabelPress, enabled, onSelectSingleSegment, onToggleSegmentSelected, onDeselectAllSegments, onSelectSegmentsByLabel, onSelectAllSegments, jumpSegStart, jumpSegEnd, addCutSegment, onViewSegmentTagsPress }) => {const { t } = useTranslation();const ref = useRef();@@ -46,15 +46,16 @@ const Segment = memo(({ seg, index, currentSegIndex, formatTimecode, getFrameCou{ type: 'separator' },- { label: t('Select ONLY current segment'), click: () => onSelectSingleSegment(seg) },+ { label: t('Select only this segment'), click: () => onSelectSingleSegment(seg) },{ label: t('Select all segments'), click: () => onSelectAllSegments() },{ label: t('Deselect all segments'), click: () => onDeselectAllSegments() },+ { label: t('Select segments by label'), click: () => onSelectSegmentsByLabel(seg) },{ type: 'separator' },{ label: t('Segment tags'), click: () => onViewSegmentTagsPress(index) },];- }, [addCutSegment, index, invertCutSegments, jumpSegEnd, jumpSegStart, onDeselectAllSegments, onSelectAllSegments, onSelectSingleSegment, onLabelPress, onRemovePress, onReorderPress, onViewSegmentTagsPress, seg, t, updateOrder]);+ }, [invertCutSegments, t, jumpSegStart, jumpSegEnd, addCutSegment, onLabelPress, onRemovePress, onReorderPress, updateOrder, onSelectSingleSegment, seg, onSelectAllSegments, onDeselectAllSegments, onSelectSegmentsByLabel, onViewSegmentTagsPress, index]);useContextMenu(ref, contextMenuTemplate);@@ -132,7 +133,7 @@ const SegmentList = memo(({currentSegIndex,updateSegOrder, updateSegOrders, addCutSegment, removeCutSegment,onLabelSegmentPress, currentCutSeg, segmentAtCursor, toggleSegmentsList, splitCurrentSegment,- selectedSegments, selectedSegmentsRaw, onSelectSingleSegment, onToggleSegmentSelected, onDeselectAllSegments, onSelectAllSegments,+ selectedSegments, selectedSegmentsRaw, onSelectSingleSegment, onToggleSegmentSelected, onDeselectAllSegments, onSelectAllSegments, onSelectSegmentsByLabel,jumpSegStart, jumpSegEnd, onViewSegmentTagsPress,}) => {const { t } = useTranslation();@@ -283,6 +284,7 @@ const SegmentList = memo(({onDeselectAllSegments={onDeselectAllSegments}onSelectAllSegments={onSelectAllSegments}onViewSegmentTagsPress={onViewSegmentTagsPress}+ onSelectSegmentsByLabel={onSelectSegmentsByLabel}/>);})}diff --git a/src/components/KeyboardShortcuts.jsx b/src/components/KeyboardShortcuts.jsxindex 5649214d..aeb7583d 100644--- a/src/components/KeyboardShortcuts.jsx+++ b/src/components/KeyboardShortcuts.jsx@@ -309,7 +309,7 @@ const KeyboardShortcuts = memo(({category: segmentsAndCutpointsCategory,},enableOnlyCurrentSegment: {- name: t('Select ONLY current segment'),+ name: t('Select only this segment'),category: segmentsAndCutpointsCategory,},disableAllSegments: {diff --git a/src/dialogs.jsx b/src/dialogs.jsxindex d4a61305..a90b54d0 100644--- a/src/dialogs.jsx+++ b/src/dialogs.jsx@@ -393,6 +393,16 @@ export async function labelSegmentDialog({ currentName, maxLength }) {return value;}+export async function selectSegmentsByLabelDialog(currentName) {+ const { value } = await Swal.fire({+ showCancelButton: true,+ title: i18n.t('Select segments by label'),+ inputValue: currentName,+ input: 'text',+ });+ return value;+}+export function openAbout() {Swal.fire({icon: 'info',