Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media replacement && Mogrt Group fix #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules/
.DS_Store
.vscode
.pretrtierignore
.example
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ This plugin adds .mogrt support to Nexrender.
2. Add this module in predownload actions
3. Add any Essential Graphics parameters you want to change as `essentialParameters`


```json
{
"template": {
Expand All @@ -25,6 +24,7 @@ This plugin adds .mogrt support to Nexrender.
"module": "nexrender-action-mogrt-template",
"essentialParameters": {
"Title": "This should be the title",
"Image": "file:///path/to/image.png",
"Dropdown": 2,
"Scale": [50, 50],
"Checkbox": true,
Expand All @@ -35,13 +35,15 @@ This plugin adds .mogrt support to Nexrender.
"Scale": [50, 50]
}
}
],

]
}
}
```

## Notes

* Any `template.src` without a .mogrt extension will be ignored
* The value in `template.composition` will be ignored, as .mogrt files specify what composition to use on their own, but Nexrender requires one to be specified
* Media replacement through essential graphics isn't supported (yet), but normal asset injection with Nexrender will work
* Invalid .mogrt files will cause an error
- Any `template.src` without a .mogrt extension will be ignored
- The value in `template.composition` will be ignored, as .mogrt files specify what composition to use on their own, but Nexrender requires one to be specified
- Like Nexrender, Medias are expected to use the file Url format.
- Invalid .mogrt files will cause an error

61 changes: 50 additions & 11 deletions applyEssentialValues.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
(function () {
function emptyDuplicate(comp, name) {
name = name || ('empty ' + comp.name);
return app.project.items.addComp(name, comp.width, comp.height, comp.pixelAspect, comp.duration, comp.frameRate);
name = name || 'empty ' + comp.name;
return app.project.items.addComp(
name,
comp.width,
comp.height,
comp.pixelAspect,
comp.duration,
comp.frameRate
);
}

function compByName(name) {
Expand All @@ -13,16 +20,48 @@
}
}

const compName = typeof _essential !== 'undefined' && _essential.get('composition') || 'Comp 1';
const essentialParameters = typeof _essential !== 'undefined' && _essential.get('essentialParameters') || {};
const templateComp = compByName(compName);
const comp = emptyDuplicate(templateComp, "__mogrt__");
function getAllProperties(prop, props) {
for (var i = 1; i <= prop.numProperties; i++) {
var currentProp = prop.property(i);
if (currentProp.numProperties > 0) {
getAllProperties(currentProp, props);
} else {
props.push(currentProp);
}
}
return props;
}

var compName =
(typeof _essential !== 'undefined' && _essential.get('composition')) ||
'Comp 1';
var essentialParameters =
(typeof _essential !== 'undefined' &&
_essential.get('essentialParameters')) ||
{};

var templateComp = compByName(compName);
var comp = emptyDuplicate(templateComp, '__mogrt__');
var layer = comp.layers.add(templateComp);
for (var i = 1; i <= layer.essentialProperty.numProperties; i++) {
var prop = layer.essentialProperty(i);
var layer = comp.layers.add(templateComp);
var essentialProperty = layer.essentialProperty;
var essentialProperties = getAllProperties(essentialProperty, [
essentialProperty,
]);

for (var p = 0; p < essentialProperties.length; p++) {
var prop = essentialProperties[p];
var value = essentialParameters[prop.name];
if (typeof value !== "undefined") {
prop.setValue(value)
if (typeof value !== 'undefined') {
if (prop.canSetAlternateSource) {
var replacementItem = app.project.importFile(
new ImportOptions(new File(value))
);
prop.setAlternateSource(replacementItem);
} else {
prop.setValue(value);
}
}
}
})();
})();

68 changes: 45 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,92 @@
const StreamZip = require('node-stream-zip');
const path = require('path');
const url = require('url');
const fs = require('fs/promises');

module.exports = async (job, settings, options, type) => {
settings.logger = settings.logger ?? console;
const jsxUrl = url.pathToFileURL(path.join(__dirname, 'applyEssentialValues.jsx')).toString();
const jsxUrl = url
.pathToFileURL(path.join(__dirname, 'applyEssentialValues.jsx'))
.toString();
if (type === 'predownload') {
if (typeof options.essentialParameters !== 'undefined') {
for (const [key, value] of Object.entries(
options.essentialParameters
)) {
if (typeof value == 'string' && value.match('file://')) {
options.essentialParameters[key] = url.fileURLToPath(value);
}
}
console.group(options.essentialParameters);

job.assets.push({
src: jsxUrl,
keyword: '_essential',
type: 'script',
parameters: [
{
key: 'essentialParameters',
value: Object.assign({}, options.essentialParameters)
}
]
})
value: Object.assign({}, options.essentialParameters),
},
],
});
}

// self-add this module as prerender action as well
if (!job.actions.prerender) {
job.actions.prerender = [];
}
job.actions.prerender.push({...options,
job.actions.prerender.push({
...options,
module: __filename,
automaticallyAdded: true
automaticallyAdded: true,
});
job.template.composition = '__mogrt__';
return job;
} else if (type === 'prerender' && options.automaticallyAdded) {
if(path.extname(job.template.dest).toLowerCase() !== ".mogrt"){
settings.logger.log(`[${job.uid}] [action-mogrt-template] skipping - template file should have .mogrt extension`);
if (path.extname(job.template.dest).toLowerCase() !== '.mogrt') {
settings.logger.log(
`[${job.uid}] [action-mogrt-template] skipping - template file should have .mogrt extension`
);
return job;
}
}

const { Mogrt } = await import('mogrt');
const mogrt = new Mogrt(job.template.dest);
await mogrt.init();

if (!mogrt.isAfterEffects()) {
throw Error('[action-mogrt-template] ERROR - .mogrt was not made with After Effects');
throw Error(
'[action-mogrt-template] ERROR - .mogrt was not made with After Effects'
);
}
const manifest = await mogrt.getManifest();
const compName = manifest.sourceInfoLocalized.en_US.name;

const asset = job.assets.find(a => a.src === jsxUrl);
const asset = job.assets.find((a) => a.src === jsxUrl);
asset.parameters.push({
key: 'composition',
value: compName
value: compName,
});

const filenames = await mogrt.extractTo(job.workpath);
const template = filenames.find(fn => path.extname(fn).toLowerCase() === '.aep');
const template = filenames.find(
(fn) => path.extname(fn).toLowerCase() === '.aep'
);
if (!template) {
throw Error(`[${job.uid}] [action-mogrt-template] ERROR - no AE file found in the .mogrt (extension .aep)`);
throw Error(
`[${job.uid}] [action-mogrt-template] ERROR - no AE file found in the .mogrt (extension .aep)`
);
}

settings.logger.log(`[${job.uid}] [action-mogrt-template] setting new template path to: ${template}`);
settings.logger.log(
`[${job.uid}] [action-mogrt-template] setting new template path to: ${template}`
);

job.template.dest = template;
job.template.extension = "aep";
job.template.extension = 'aep';
return job;
} else {
throw Error("'action-mogrt-template' module should be used only in 'predownload' section");
throw Error(
"'action-mogrt-template' module should be used only in 'predownload' section"
);
}
}
};

49 changes: 25 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"name": "nexrender-action-mogrt-template",
"version": "0.0.4",
"description": "MOGRT support for Nexrender",
"main": "index.js",
"scripts": {
"test": "node --experimental-vm-modules ./node_modules/.bin/jest "
},
"repository": {
"type": "git",
"url": "git+https://github.com/vonstring/nexrender-action-mogrt-template.git"
},
"author": "Kristian von Streng Hæhre",
"license": "ISC",
"bugs": {
"url": "https://github.com/vonstring/nexrender-action-mogrt-template/issues"
},
"homepage": "https://github.com/vonstring/nexrender-action-mogrt-template#readme",
"dependencies": {
"mogrt": "^0.0.2",
"node-stream-zip": "^1.15.0"
},
"devDependencies": {
"jest": "^28.1.3"
}
"name": "nexrender-action-mogrt-template",
"version": "0.0.4",
"description": "MOGRT support for Nexrender",
"main": "index.js",
"scripts": {
"test": "node --experimental-vm-modules ./node_modules/.bin/jest "
},
"repository": {
"type": "git",
"url": "git+https://github.com/vonstring/nexrender-action-mogrt-template.git"
},
"author": "Kristian von Streng Hæhre",
"license": "ISC",
"bugs": {
"url": "https://github.com/vonstring/nexrender-action-mogrt-template/issues"
},
"homepage": "https://github.com/vonstring/nexrender-action-mogrt-template#readme",
"dependencies": {
"mogrt": "^0.0.2",
"node-stream-zip": "^1.15.0"
},
"devDependencies": {
"jest": "^28.1.3"
}
}