From 08d9976482b3cb0e2e5c9840a0980bae767fa0a0 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sat, 26 Nov 2016 00:10:15 +0100 Subject: [PATCH] Implement custom output dir button --- src/ffmpeg.js | 19 +++++++++++-------- src/renderer.jsx | 25 +++++++++++++++++++++---- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/ffmpeg.js b/src/ffmpeg.js index ac924d35..7d27dac6 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -28,18 +28,21 @@ function canExecuteFfmpeg(ffmpegPath) { function getFfmpegPath() { const internalFfmpeg = path.join(__dirname, '..', 'app.asar.unpacked', 'ffmpeg', getWithExt('ffmpeg')); return canExecuteFfmpeg(internalFfmpeg) - .then(() => internalFfmpeg) - .catch(() => { - console.log('Internal ffmpeg unavail'); - return which('ffmpeg'); - }); + .then(() => internalFfmpeg) + .catch(() => { + console.log('Internal ffmpeg unavail'); + return which('ffmpeg'); + }); } -function cut(filePath, format, cutFrom, cutTo) { +function cut(outputDir, filePath, format, cutFrom, cutTo) { return bluebird.try(() => { const ext = path.extname(filePath) || `.${format}`; - const outFileAppend = `${util.formatDuration(cutFrom)}-${util.formatDuration(cutTo)}`; - const outFile = `${filePath}-${outFileAppend}${ext}`; + const duration = `${util.formatDuration(cutFrom)}-${util.formatDuration(cutTo)}`; + const basename = path.basename(filePath); + const outFile = outputDir ? + path.join(outputDir, `${basename}-${duration}${ext}`) : + `${filePath}-${duration}${ext}`; console.log('Cutting from', cutFrom, 'to', cutTo); diff --git a/src/renderer.jsx b/src/renderer.jsx index 2f4f9646..8c7003ba 100644 --- a/src/renderer.jsx +++ b/src/renderer.jsx @@ -4,6 +4,7 @@ const keyboardJs = require('keyboardjs'); const _ = require('lodash'); const captureFrame = require('capture-frame'); const fs = require('fs'); +const path = require('path'); const Hammer = require('react-hammerjs'); const React = require('react'); @@ -13,6 +14,8 @@ const classnames = require('classnames'); const ffmpeg = require('./ffmpeg'); const util = require('./util'); +const dialog = electron.remote.dialog; + function getVideo() { return $('#player video')[0]; } @@ -131,6 +134,12 @@ class App extends React.Component { this.setState({ cutEndTime: this.state.currentTime }); } + setOutputDir() { + dialog.showOpenDialog({ properties: ['openDirectory'] }, (paths) => { + this.setState({ outputDir: (paths && paths.length === 1) ? paths[0] : undefined }); + }); + } + jumpCutStart() { seekAbs(this.state.cutStartTime); } @@ -191,7 +200,9 @@ class App extends React.Component { } this.setState({ working: true }); - return ffmpeg.cut(filePath, this.state.fileFormat, cutStartTime, cutEndTime) + const outputDir = this.state.outputDir; + const fileFormat = this.state.fileFormat; + return ffmpeg.cut(outputDir, filePath, fileFormat, cutStartTime, cutEndTime) .catch((err) => { console.error('stdout:', err.stdout); console.error('stderr:', err.stderr); @@ -283,7 +294,7 @@ class App extends React.Component {
this.setCutEnd()} />
+