diff --git a/package.json b/package.json index 640e0e7..076f738 100644 --- a/package.json +++ b/package.json @@ -136,6 +136,9 @@ "asar": { "smartUnpack": false }, + "asarUnpack": [ + "node_modules/exiftool-vendored.*/**/*" + ], "appId": "no.mifi.losslesscut", "artifactName": "${productName}-${os}.${ext}", "afterSign": "electron-builder-notarize", @@ -417,5 +420,9 @@ "removable-media" ] } + }, + "optionalDependencies": { + "exiftool-vendored.exe": "^12.40.0", + "exiftool-vendored.pl": "^12.40.0" } } diff --git a/src/exiftool.js b/src/exiftool.js new file mode 100644 index 0000000..73445b8 --- /dev/null +++ b/src/exiftool.js @@ -0,0 +1,25 @@ +const isDev = window.require('electron-is-dev'); +const os = window.require('os'); +const { join } = window.require('path'); +const execa = window.require('execa'); + +function getPath() { + const platform = os.platform(); + + // todo test asar + // todo correct? + const subPath = platform === 'win32' ? 'exiftool-vendored.exe/bin/exiftool.exe' : 'exiftool-vendored.pl/bin/exiftool'; + + const path = `node_modules/${subPath}`; + return isDev ? path : join(process.resourcesPath, 'app.asar.unpacked', path); +} + +// eslint-disable-next-line import/prefer-default-export +export async function exifToolCopyMeta(inPath, outPath) { + /* const existingTags = await exiftool.read(inPath); + console.log('existing tags', existingTags); + await await exiftool.write(outPath, existingTags); */ + console.log('Copying exif data'); + await execa(getPath(), ['-tagsFromFile', inPath, '-all:all', '-overwrite_original', outPath]); + console.log('Done copying exif data'); +} diff --git a/src/hooks/useFfmpegOperations.js b/src/hooks/useFfmpegOperations.js index 494e6fe..bf41e62 100644 --- a/src/hooks/useFfmpegOperations.js +++ b/src/hooks/useFfmpegOperations.js @@ -6,6 +6,7 @@ import pMap from 'p-map'; import { getOutPath, transferTimestamps, getOutFileExtension, getOutDir, isMac, deleteDispositionValue } from '../util'; import { isCuttingStart, isCuttingEnd, handleProgress, getFfCommandLine, getFfmpegPath, getDuration, runFfmpeg, createChaptersFromSegments } from '../ffmpeg'; +import { exifToolCopyMeta } from '../exiftool'; const execa = window.require('execa'); const { join, resolve } = window.require('path'); @@ -52,11 +53,17 @@ function getMatroskaFlags() { const getChaptersInputArgs = (ffmetadataPath) => (ffmetadataPath ? ['-f', 'ffmetadata', '-i', ffmetadataPath] : []); +const enableExifToolCopyMeta = true; //todo + function useFfmpegOperations({ filePath, enableTransferTimestamps }) { const optionalTransferTimestamps = useCallback(async (...args) => { if (enableTransferTimestamps) await transferTimestamps(...args); }, [enableTransferTimestamps]); + const optionalExifToolCopyMeta = useCallback(async (...args) => { + if (enableExifToolCopyMeta) await exifToolCopyMeta(...args); + }, []); + // const cut = useCallback(, [filePath, optionalTransferTimestamps]); const cutMultiple = useCallback(async ({ @@ -205,6 +212,7 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) { const result = await process; console.log(result.stdout); + await optionalExifToolCopyMeta(filePath, outPath); await optionalTransferTimestamps(filePath, outPath, cutFrom); } @@ -232,7 +240,7 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) { } return outFiles; - }, [filePath, optionalTransferTimestamps]); + }, [filePath, optionalTransferTimestamps, optionalExifToolCopyMeta]); const mergeFiles = useCallback(async ({ paths, outDir, outPath, allStreams, outFormat, ffmpegExperimental, onProgress = () => {}, preserveMovData, movFastStart, chapters, preserveMetadataOnMerge }) => { console.log('Merging files', { paths }, 'to', outPath); @@ -337,8 +345,9 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) { if (chaptersPath) await fs.unlink(chaptersPath).catch((err) => console.error('Failed to delete', chaptersPath, err)); } + await optionalExifToolCopyMeta(paths[0], outPath); await optionalTransferTimestamps(paths[0], outPath); - }, [optionalTransferTimestamps]); + }, [optionalTransferTimestamps, optionalExifToolCopyMeta]); const autoMergeSegments = useCallback(async ({ customOutDir, isCustomFormatSelected, outFormat, segmentPaths, ffmpegExperimental, onProgress, preserveMovData, movFastStart, autoDeleteMergedSegments, chapterNames, preserveMetadataOnMerge }) => { const ext = getOutFileExtension({ isCustomFormatSelected, outFormat, filePath }); diff --git a/yarn.lock b/yarn.lock index 4bd8af0..3e5b254 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5110,6 +5110,16 @@ execa@^5.0.0: signal-exit "^3.0.3" strip-final-newline "^2.0.0" +exiftool-vendored.exe@^12.40.0: + version "12.40.0" + resolved "https://registry.yarnpkg.com/exiftool-vendored.exe/-/exiftool-vendored.exe-12.40.0.tgz#0285fb4fc3b4495aa4c41f3784eb69b7d001a1c6" + integrity sha512-Ng7CGioXkX3msJzI8HxM5ZbtoUiw/4JFJSxe9d/kOqOo3nMqStB8sqtwjmilsHAyuW2JIGkUtZ+IxPkuzRrmyA== + +exiftool-vendored.pl@^12.40.0: + version "12.40.0" + resolved "https://registry.yarnpkg.com/exiftool-vendored.pl/-/exiftool-vendored.pl-12.40.0.tgz#484b45114193167d67178f9c59af104fe8d9f177" + integrity sha512-yNoDhG6g8ifzgm0PPqgWTiI5vdbuTGyTgIlpy+hxeuf7M2b0x6tGtYNakjIO9Q08VDNxXIr1lEZJR2EMZ5JDTQ== + exit@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c"