Skip to content

Commit

Permalink
Save export options to project
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript committed Dec 10, 2022
1 parent 8ee2a91 commit 4b8694b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
27 changes: 27 additions & 0 deletions htdocs/fcut-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ function readFile(filename, asJson) {
});
}

function getJson(response) {
return response.json();
}

function rejectIfNotOk(response) {
if (response.ok) {
return response;
}
return Promise.reject(response.statusText);
}

function hashString(s) {
var h = 0;
if (typeof s !== 'string') {
Expand All @@ -210,3 +221,19 @@ function hashString(s) {
}
return h;
}

function isObject(obj) {
return (obj !== null) && (typeof obj === 'object');
}

function copyFields(target, source, fields) {
if (isObject(target) && isObject(source) && Array.isArray(fields)) {
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
if (source.hasOwnProperty(field)) {
target[field] = source[field];
}
}
}
return target;
}
21 changes: 10 additions & 11 deletions htdocs/fcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var endRegExp = /^\n -- exit code ([0-9]+)\s/;
var DEFAULT_DESTINATION_FILENAME = 'fcut-out.mp4';
var DEFAULT_PROJECT_FILENAME = 'fcut-project.json';

var EXPORTED_FIELDS = ['destinationFilename', 'projectFilename', 'aspectRatio', 'exportFormat', 'exportVideoCodec', 'exportAudioCodec', 'exportSubtitleCodec', 'exportMapAllStreams', 'time'];

function updatePart(part) {
if (typeof part === 'object') {
var u = hashString(part.sourceId + (part.from | 0).toString(16));
Expand Down Expand Up @@ -93,9 +95,7 @@ var vm = new Vue({
file: filename,
extention: extention
})
}).then(function(response) {
return response.json();
}).then(function(filenames) {
}).then(getJson).then(function(filenames) {
if (filenames && (filenames.length > 0)) {
if (multiple) {
return filenames;
Expand Down Expand Up @@ -139,11 +139,10 @@ var vm = new Vue({
},
loadConfig: function(boot) {
var that = this;
return Promise.all([fetch('config/').then(function(response) {
return response.json();
}), fetch('/rest/checkFFmpeg', { method: 'POST' }).then(function(response) {
return response.json();
})]).then(function(values) {
return Promise.all([
fetch('config/').then(getJson),
fetch('/rest/checkFFmpeg', { method: 'POST' }).then(getJson)
]).then(function(values) {
var config = values[0];
var checkFFmpeg = values[1];
//console.info('config', config, 'checkFFmpeg', checkFFmpeg);
Expand Down Expand Up @@ -171,9 +170,7 @@ var vm = new Vue({
},
openSourceById: function(sourceId) {
var that = this;
return fetch('source/' + sourceId + '/info.json').then(function(response) {
return response.json();
}).then(function(info) {
return fetch('source/' + sourceId + '/info.json').then(getJson).then(function(info) {
//console.info('info', info);
that.sources[sourceId] = info;
return sourceId;
Expand Down Expand Up @@ -501,6 +498,7 @@ var vm = new Vue({
parts: this.parts,
sources: sources
};
copyFields(project, this, EXPORTED_FIELDS);
return project;
},
loadProjectFromJson: function(project) {
Expand All @@ -515,6 +513,7 @@ var vm = new Vue({
});
})).then(function() {
that.parts = project.parts;
copyFields(that, project, EXPORTED_FIELDS);
that.refreshParts();
that.navigateTo(0);
});
Expand Down

0 comments on commit 4b8694b

Please sign in to comment.