mirror of
https://github.com/mifi/lossless-cut.git
synced 2024-11-25 03:33:14 +01:00
Fix file-opened which returns an array
This fixes a crash when cutting after opening with ctrl+O Also add more intelligent format detection. Beause ffprobe only returns a list of formats
This commit is contained in:
parent
b9019af2ed
commit
62c29af1de
@ -47,12 +47,14 @@
|
|||||||
"electron": "^1.4.5",
|
"electron": "^1.4.5",
|
||||||
"electron-default-menu": "^1.0.0",
|
"electron-default-menu": "^1.0.0",
|
||||||
"execa": "^0.5.0",
|
"execa": "^0.5.0",
|
||||||
|
"file-type": "^3.9.0",
|
||||||
"jquery": "^3.1.1",
|
"jquery": "^3.1.1",
|
||||||
"keyboardjs": "^2.3.3",
|
"keyboardjs": "^2.3.3",
|
||||||
"lodash": "^4.16.4",
|
"lodash": "^4.16.4",
|
||||||
"react": "^15.3.2",
|
"react": "^15.3.2",
|
||||||
"react-dom": "^15.3.2",
|
"react-dom": "^15.3.2",
|
||||||
"react-hammerjs": "^0.5.0",
|
"react-hammerjs": "^0.5.0",
|
||||||
|
"read-chunk": "^2.0.0",
|
||||||
"which": "^1.2.11"
|
"which": "^1.2.11"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,12 @@ const execa = require('execa');
|
|||||||
const bluebird = require('bluebird');
|
const bluebird = require('bluebird');
|
||||||
const which = bluebird.promisify(require('which'));
|
const which = bluebird.promisify(require('which'));
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const util = require('./util');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const fileType = require('file-type');
|
||||||
|
const readChunk = require('read-chunk');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const util = require('./util');
|
||||||
|
|
||||||
bluebird.promisifyAll(fs);
|
bluebird.promisifyAll(fs);
|
||||||
|
|
||||||
@ -56,7 +60,7 @@ function cut(filePath, format, cutFrom, cutTo) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFormats(filePath) {
|
function getFormat(filePath) {
|
||||||
return bluebird.try(() => {
|
return bluebird.try(() => {
|
||||||
console.log('getFormat', filePath);
|
console.log('getFormat', filePath);
|
||||||
|
|
||||||
@ -68,14 +72,21 @@ function getFormats(filePath) {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
const formatsStr = JSON.parse(result.stdout).format.format_name;
|
const formatsStr = JSON.parse(result.stdout).format.format_name;
|
||||||
console.log('formats', formatsStr);
|
console.log('formats', formatsStr);
|
||||||
const formats = formatsStr.split(',');
|
const formats = (formatsStr || '').split(',');
|
||||||
return formats;
|
|
||||||
|
// ffprobe sometimes returns a list of formats, try to be a bit smarter about it.
|
||||||
|
return readChunk(filePath, 0, 262)
|
||||||
|
.then((bytes) => {
|
||||||
|
const ft = fileType(bytes);
|
||||||
|
if (_.includes(formats, ft.ext)) return ft.ext;
|
||||||
|
return formats[0] || undefined;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
cut,
|
cut,
|
||||||
getFormats,
|
getFormat,
|
||||||
showFfmpegFail,
|
showFfmpegFail,
|
||||||
};
|
};
|
||||||
|
@ -19,8 +19,8 @@ module.exports = (app, mainWindow) => {
|
|||||||
label: 'Open',
|
label: 'Open',
|
||||||
accelerator: 'CmdOrCtrl+O',
|
accelerator: 'CmdOrCtrl+O',
|
||||||
click() {
|
click() {
|
||||||
dialog.showOpenDialog({ properties: ['openFile'] }, (data) => {
|
dialog.showOpenDialog({ properties: ['openFile'] }, (filePaths) => {
|
||||||
mainWindow.webContents.send('file-opened', data);
|
mainWindow.webContents.send('file-opened', filePaths);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -65,15 +65,17 @@ class App extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const load = (filePath) => {
|
const load = (filePath) => {
|
||||||
|
console.log('Load', filePath);
|
||||||
if (this.state.working) return alert('I\'m busy');
|
if (this.state.working) return alert('I\'m busy');
|
||||||
|
|
||||||
resetState();
|
resetState();
|
||||||
|
|
||||||
this.setState({ working: true });
|
this.setState({ working: true });
|
||||||
return ffmpeg.getFormats(filePath)
|
|
||||||
.then((formats) => {
|
return ffmpeg.getFormat(filePath)
|
||||||
if (formats.length < 1) return alert('Unsupported file');
|
.then((fileFormat) => {
|
||||||
return this.setState({ filePath, fileFormat: formats[0] });
|
if (!fileFormat) return alert('Unsupported file');
|
||||||
|
return this.setState({ filePath, fileFormat });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.code === 1) {
|
if (err.code === 1) {
|
||||||
@ -85,9 +87,9 @@ class App extends React.Component {
|
|||||||
.finally(() => this.setState({ working: false }));
|
.finally(() => this.setState({ working: false }));
|
||||||
};
|
};
|
||||||
|
|
||||||
electron.ipcRenderer.on('file-opened', (event, message) => {
|
electron.ipcRenderer.on('file-opened', (event, filePaths) => {
|
||||||
if (!message) return;
|
if (!filePaths || filePaths.length !== 1) return;
|
||||||
load(message);
|
load(filePaths[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.ondragover = document.ondragend = ev => ev.preventDefault();
|
document.ondragover = document.ondragend = ev => ev.preventDefault();
|
||||||
|
@ -1 +1 @@
|
|||||||
for f in sample-videos/*; do echo -n "$f: "; ffprobe -show_format -of json -i "$f" | json format.format_name; done 2> /dev/null
|
for f in *; do echo -n "$f: "; ffprobe -show_format -of json -i "$f" | json format.format_name; done 2> /dev/null
|
||||||
|
Loading…
Reference in New Issue
Block a user