implement export single track

pull/699/head
Mikael Finstad 2021-02-21 19:13:04 +01:00
rodzic d5e03784d7
commit 6093acee63
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 25AB36E3E81CBC26
2 zmienionych plików z 25 dodań i 7 usunięć

Wyświetl plik

@ -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}

Wyświetl plik

@ -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
<td>
<FaInfoCircle role="button" onClick={() => onInfoClick(stream, t('Track info'))} size={22} />
<FiEdit title={t('Edit track metadata')} role="button" size={20} style={{ padding: '0 5px' }} onClick={() => setEditingStream({ streamId: stream.index, path: filePath })} />
<FaFileExport title={t('Extract this track as file')} role="button" onClick={onExtractStreamPress} size={18} />
</td>
</tr>
);
@ -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)}
/>
))}
</tbody>