From 6093acee637ea3e3c5e0ce8a67596d38c1c6233a Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sun, 21 Feb 2021 19:13:04 +0100 Subject: [PATCH] implement export single track --- src/App.jsx | 26 +++++++++++++++++++++----- src/StreamsSelector.jsx | 6 ++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index f46fdd83..c3b658e3 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1144,6 +1144,9 @@ const App = memo(() => { const validEdl = edl.filter((row) => ( (row.start === undefined || row.end === undefined || row.start < row.end) && (row.start === undefined || row.start >= 0) + // TODO: Cannot do this because duration is not yet set when loading a file + // && (row.start === undefined || (row.start >= 0 && row.start < duration)) + // && (row.end === undefined || row.end < duration) )); if (validEdl.length === 0) throw new Error(i18n.t('No valid segments found')); @@ -1431,6 +1434,22 @@ const App = memo(() => { electron.ipcRenderer.send('setAskBeforeClose', askBeforeClose && isFileOpened); }, [askBeforeClose, isFileOpened]); + const extractSingleStream = useCallback(async (index) => { + if (!filePath || working) return; + + try { + // setStreamsSelectorShown(false); + setWorking(i18n.t('Extracting track')); + await extractStreams({ customOutDir, filePath, streams: mainStreams.filter((s) => s.index === index) }); + openDirToast({ dirPath: outputDir, text: i18n.t('Track has been extracted') }); + } catch (err) { + errorToast(i18n.t('Failed to extract track')); + console.error('Failed to extract track', err); + } finally { + setWorking(); + } + }, [customOutDir, filePath, mainStreams, outputDir, working]); + const extractAllStreams = useCallback(async () => { if (!filePath) return; @@ -1449,10 +1468,6 @@ const App = memo(() => { } }, [customOutDir, filePath, mainStreams, outputDir]); - function onExtractAllStreamsPress() { - extractAllStreams(); - } - const addStreamSourceFile = useCallback(async (path) => { if (externalStreamFiles[path]) return; const { streams } = await getAllStreams(path); @@ -2022,7 +2037,8 @@ const App = memo(() => { isCopyingStreamId={isCopyingStreamId} toggleCopyStreamId={toggleCopyStreamId} setCopyStreamIdsForPath={setCopyStreamIdsForPath} - onExtractAllStreamsPress={onExtractAllStreamsPress} + onExtractAllStreamsPress={extractAllStreams} + onExtractStreamPress={extractSingleStream} areWeCutting={areWeCutting} shortestFlag={shortestFlag} setShortestFlag={setShortestFlag} diff --git a/src/StreamsSelector.jsx b/src/StreamsSelector.jsx index 2215d0ee..3374e198 100644 --- a/src/StreamsSelector.jsx +++ b/src/StreamsSelector.jsx @@ -173,7 +173,7 @@ function onInfoClick(s, title) { }); } -const Stream = memo(({ filePath, stream, onToggle, copyStream, fileDuration, setEditingStream }) => { +const Stream = memo(({ filePath, stream, onToggle, copyStream, fileDuration, setEditingStream, onExtractStreamPress }) => { const { t } = useTranslation(); const bitrate = parseInt(stream.bit_rate, 10); @@ -213,6 +213,7 @@ const Stream = memo(({ filePath, stream, onToggle, copyStream, fileDuration, set onInfoClick(stream, t('Track info'))} size={22} /> setEditingStream({ streamId: stream.index, path: filePath })} /> + ); @@ -256,7 +257,7 @@ const fileStyle = { marginBottom: 10, backgroundColor: 'rgba(0,0,0,0.04)', paddi const StreamsSelector = memo(({ mainFilePath, mainFileFormatData, streams: mainFileStreams, isCopyingStreamId, toggleCopyStreamId, - setCopyStreamIdsForPath, onExtractAllStreamsPress, externalFiles, setExternalFiles, + setCopyStreamIdsForPath, onExtractStreamPress, onExtractAllStreamsPress, externalFiles, setExternalFiles, showAddStreamSourceDialog, shortestFlag, setShortestFlag, nonCopiedExtraStreams, AutoExportToggler, customTagsByFile, setCustomTagsByFile, customTagsByStreamId, setCustomTagsByStreamId, }) => { @@ -303,6 +304,7 @@ const StreamsSelector = memo(({ onToggle={(streamId) => toggleCopyStreamId(mainFilePath, streamId)} setEditingStream={setEditingStream} fileDuration={getFormatDuration(mainFileFormatData)} + onExtractStreamPress={() => onExtractStreamPress(stream.index)} /> ))}