-
Notifications
You must be signed in to change notification settings - Fork 1
/
libtl_Conform_from_Tc.jsxinc
572 lines (507 loc) · 20.1 KB
/
libtl_Conform_from_Tc.jsxinc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
/**
* Extends After Effects Objects for the Conformation script
* @version 1.1s
*/
//PROJET PART
function findFolderWithName (name, createIt) {
var create = createIt || undefined;
var item;
var project = app.project;
for(var i=1;i<=project.numItems;i++) {
if (project.item(i) instanceof FolderItem && project.item(i).name === name){
item = project.item(i);
break;
}
}
if (createIt && !item) {
item = project.items.addFolder(name)
}
return item;
}
function findCompWithName (name) {
var item = null;
var project = app.project;
for(var i=1;i<=project.numItems;i++) {
if (project.item(i) instanceof CompItem && project.item(i).name === name){
item = project.item(i);
break;
}
}
return item;
}
//FOLDER PART
function getLastDotOfFile (scannedFile){
var dot = 0;
if ($.os.indexOf ("Windows") !=-1){
dot = scannedFile.lastIndexOf(".");
}
else {
dot = scannedFile.lastIndexOf(".");
}
return dot;
}
function getLastSlashofFilePath (scannedFile){
var slash = 0;
if ($.os.indexOf ("Windows") !=-1){
var delimitationStr = "\\";
slash = scannedFile.lastIndexOf (delimitationStr);
}
else {
slash = scannedFile.lastIndexOf("/");
}
return slash;
}
function splitFileName(scannedFile){
if (scannedFile != null) {
var dot = getLastDotOfFile (scannedFile);
var slash = getLastSlashofFilePath (scannedFile);
var fileExt = scannedFile.substr( dot, scannedFile.length);
var scannedFileWithoutExt = scannedFile.substr (0, dot);
var parentFileFolder = scannedFileWithoutExt.substr (0, slash);
var reelNameAndTimeCode = scannedFileWithoutExt.substr (slash+1, scannedFileWithoutExt.toString().length);
var reelName = "";
var timeCode = 0;
var splitArray = [];
for ( var a=reelNameAndTimeCode.length-1; a>0; a--){
//if char (a) is not a number --> end of the TimeCode description
if ( isNaN(reelNameAndTimeCode.charAt(a) ) ||
(reelNameAndTimeCode.charAt(a) === ".") ){
reelName = reelNameAndTimeCode.substring(0, (a) );
timeCode = parseInt (reelNameAndTimeCode.substr ( ( a+1), dot), 10);
splitArray.push ( parentFileFolder,reelName, timeCode, fileExt);
break;
}
}
return splitArray;
}
else{
return null;
}
}
/**
* getCleanLayerSourceFile (in fsname)
* @param {layer}
* @returns {file.fsNAme} or {layerName}
*/
function getCleanLayerSourceFile (layer) {
var sourceFile ="";
try {
if (layer.source.file) {
sourceFile = layer.source.file.fsName;
}
}
catch (e) {
sourceFile = layer.name;
}
return sourceFile;
}
function getLayerSourceReelName (layer) {
try {
var reelName = layer.name;
if (layer.source.file) {
var sourceFile = layer.source.file;
var sourceFileStr = sourceFile.toString();
var dot = getLastDotOfFile (sourceFileStr);
var slash = getLastSlashofFilePath (sourceFileStr);
reelName =sourceFileStr.substring (slash+1, dot);
}
return reelName
}catch (e){
alert (e)
}
}
function makeFilterList (filterArray){
var filterList = "(";
for (var i =0; i< filterArray.length; i ++)
{
if (i ==0){
filterList += "\\"+filterArray[i];
}
else {
filterList += "|"+'\\'+filterArray[i];
}
}
filterList += ")";
return filterList;
}
/**
* Retrieve all files recursively matching filter
* @param {String|RegExp} filter
* @returns {Array} Array of file Objects {temporary window} With progressBar
*/
function scanFilesWithProgressBar (folder,filter) {
var filelist = [];
var files = folder.getFiles();
var tempWindow = new Window('palette');
tempWindow.info = tempWindow.add("staticText",[0,0,200,50], "Scanning Files");
tempWindow.progressScan = tempWindow.add("progressBar", undefined, 0, files.length);
tempWindow.progressScan.preferredSize.width = 300;
tempWindow.show();
for (var i=0; i<files.length; i++) {
tempWindow .progressScan.value = i;
var file = files[i];
if (file instanceof Folder) {
var list = scanFilesWithProgressBar(file, filter)
for(var j=0; j<list.length; j++) { filelist.push(list[j]); }
} else if (file instanceof File) {
if (file.name.match(filter)) filelist.push(file);
}
}
tempWindow.close();
return filelist;
}
//FsName
/**
* @@param {Array}String}
* @returns Array {fsName}
*/
function convertTofsName (list){
for (var i=0; i< list.length; i++)
{
list[i] =list[i].fsName;
}
return list;
}
//cmd WindowsOs Functions
function listFilesWinOs (folder,filterArray) {
var FsNFolder = folder.fsName;
try{
var fsProjFolder = app.project.file.parent.fsName;
}
catch(e){
alert ("please, save your project before")
return []
}
var listFiles= [];
for (var i =0; i <filterArray.length; i++)
{
var command = 'cmd.exe /c dir '+ FsNFolder+'\\*'+filterArray[i].toString()+' /s/b/o:n >>'+ fsProjFolder+'\\listSeq.txt';
system.callSystem(command);
}
var listf= File (fsProjFolder+'\\listSeq.txt');
listf.open("r");
var listff = listf.read();
listFiles = listff.split(/\r\n|\n/);
listf.close();
system.callSystem('cmd.exe /c del '+fsProjFolder+'\\listSeq.txt');
return listFiles;
}
function checkMediaInfoWinOs() {
var mediaInfoInstalled = false;
var thisFile = new File($.fileName);
var basePath = Folder (thisFile.parent.fsName); //script location
var files = basePath.getFiles();
for (var i=0; i<files.length; i++) {
var file = files[i];
if (file.name === "MediaInfo_CLI" &&file instanceof Folder)
{
var subFiles = file.getFiles();
for (var j=0; j<subFiles.length; j++) {
if (subFiles[j].name.toString() ==="MediaInfo.exe") {
mediaInfoInstalled = true;
break;
}
}
break
}
}
return mediaInfoInstalled
}
/**
* @param {folder} folder, array, int}
* @returns Array {mediainfo}
*/
function cmdListMediasInFoldersWinOs(folder, filterArray, sequenceNumber) {
try{
var fsProjFolder = app.project.file.parent.fsName;
}
catch(e){
alert ("please, save your project before")
return []
}
try{
var FsNFolder = folder.fsName;
var thisFile = new File($.fileName);
var scriptPath = thisFile.parent;
for (var i =0; i <filterArray.length; i++){
var command = 'cmd.exe /c dir '+ FsNFolder+'\\*'+filterArray[i].toString()+' /s/b/o:n >>'+ fsProjFolder+'\\listSeq.txt';
system.callSystem(command);
}
var listf= File (fsProjFolder+'\\listSeq.txt');
listf.open("r");
listff = listf.read();
var listMedia = listff.split(/\r\n|\n/);
listf.close();
for (var i =0; i< listMedia.length; i++)
{
var commandMedia = 'cmd.exe /c "'+scriptPath.fsName+'\\MediaInfo_CLI\\MediaInfo.exe" --Output "'+listMedia[i]+'" >>"'+fsProjFolder+'\\listMedias.txt"';
system.callSystem(commandMedia);
}
var listmedias= File (fsProjFolder+"\\listMedias.txt");
listmedias.open("r");
var listglobal = listmedias.read();
if (listglobal.toString().indexOf ("General") ==-1){
system.callSystem('cmd.exe /c del '+fsProjFolder+'\\listMedias.txt');
system.callSystem('cmd.exe /c del '+fsProjFolder+'\\listSeq.txt');
return [sequenceNumber]};
var mediaNumber =sequenceNumber; // list number of detected sequences
var mediaListArray= []; //array to list class of each sequences
var listInfo = listglobal.split("\n");
//separate each media in the list
media = splitMediaInfos (listInfo);
mediaListArray.unshift(mediaNumber);
system.callSystem('cmd.exe /c del '+fsProjFolder+'\\listMedias.txt');
system.callSystem('cmd.exe /c del '+fsProjFolder+'\\istSeq.txt');
return mediaListArray;
}
catch(e){
alert (e)
}
}
//terminal MacOs functions
/**
* @@param {string)
* @returns String. with unix space notation}
*/
function killspaceForUnix(name){
if (name.toString().indexOf (" ") !=-1){
newName = name.toString().replace(/\s/g,'\\ ');
}
else
{
newName = name;
}
return newName
;
}
/**
* @@param {Folder} folder, String}
* @returns Array {string list Files}
*/
function listFilesMacOs (folder,filterArray) {
var FsNFolder = folder.fsName;
var unixFolder = killspaceForUnix(FsNFolder);
var listFiles= [];
for (var i =0; i <filterArray.length; i++)
{
var command = 'find '+unixFolder+' -type f -name "*'+filterArray[i].toString()+'" |sort >>'+unixFolder+'/listSeq.txt';
system.callSystem(command);
}
var listf= File (FsNFolder +"/listSeq.txt");
listf.open("r");
listff = listf.read();
listFiles = listff.split(/\r\n|\n/);
listf.close();
system.callSystem('rm '+ unixFolder+'/listSeq.txt');
return listFiles;
}
//Media Info functions
/**
* @param {folder} folder to create a temporary test file
* @returns bool} mediainfo) installed or not
*/
function checkMediaInfoMacOs (folder) {
var FsNFolder = folder.fsName;
var unixFolder = killspaceForUnix(FsNFolder);
var commandTerminal= '/usr/local/bin/mediainfo >>'+unixFolder+'/test.txt ';
system.callSystem(commandTerminal);
try
{
var testFile= File (FsNFolder +'/test.txt');
system.callSystem('rm '+ unixFolder+'/test.txt');
return true
}
catch (e)
{
return false
}
}
/**
* @param {String} mediainfo line
* @returns {String} mediainfo interrresting info part after the :)
*/
function extractMediaInfo (thisString){
var newString = thisString.toString().substring(thisString.toString().indexOf(":")+1);
return newString
}
/**
* @param {folder} folder, array, int}
* @returns Array {mediainfo}
*/
function cmdListMediasInFoldersMacOs(folder, filterArray, sequenceNumber) {
try{
var FsNFolder = folder.fsName;
var unixFolder = killspaceForUnix(FsNFolder);
if (system.osName.toString().indexOf("Mac") !=-1) {
for (var i =0; i <filterArray.length; i++){
var command = 'find '+unixFolder+' -type f -name "*'+filterArray[i].toString()+'" |sort >>'+unixFolder+'/listSeq.txt';
system.callSystem(command);
}
var listf= File (FsNFolder +"/listSeq.txt");
}
listf.open("r");
listff = listf.read();
var listMedia = listff.split(/\r\n|\n/);
listf.close();
for (var i =0; i< listMedia.length; i++)
{
var unixMedia = killspaceForUnix(listMedia[i]);
var commandMedia= '/usr/local/bin/mediainfo --Output '+unixMedia+' >>'+unixFolder+'/listMedias.txt ';
system.callSystem(commandMedia);
}
var listmedias= File (FsNFolder +"/listMedias.txt");
if (!listmedias) {alert ("Media info is not installed"); return}
listmedias.open("r");
var listglobal = listmedias.read();
if (listglobal.toString().indexOf ("General") ==-1){
system.callSystem('rm '+ unixFolder +"/listMedias.txt");
system.callSystem('rm '+ unixFolder+'/listSeq.txt');
return [sequenceNumber]};
var mediaNumber =sequenceNumber; // list number of detected sequences
var mediaListArray= []; //array to list class of each sequences
var listInfo = listglobal.split("\n");
//separate each media in the list
var media= splitMediaInfos (listInfo);
mediaListArray.push (media)
mediaListArray.unshift(mediaNumber);
system.callSystem('rm '+unixFolder+'/listSeq.txt');
system.callSystem('rm '+unixFolder+"/listMedias.txt");
return mediaListArray;
}
catch(e){
alert (e)
}
}
//Media info split info for mac and windows
function splitMediaInfos (listInfo){
var media= {};
for (var i =0; i< listInfo.length; i++){
if (listInfo[i].toString().indexOf ("General") !=-1){
mediaNumber +=1;
media.mediaMatricule =mediaNumber ;
}
if (listInfo [i].toString().indexOf ("Complete name") !=-1){
media.fullFile = extractMediaInfo (listInfo[i].toString());
media.fileExtension = media.fullFile.substring(media.fullFile.lastIndexOf("."));
media.reelName = media.fullFile.substring (media.fullFile.lastIndexOf("/")+1,media.fullFile.lastIndexOf(".") );
media.fileFolder = media.fullFile.substring (0, media.fullFile.lastIndexOf("/"));
}
if (listInfo[i].toString().indexOf ("Frame rate") !=-1){
media.frameRate = parseFloat (extractMediaInfo (listInfo[i].toString()));
}
if (listInfo[i].toString().indexOf ("TIM") !=-1){
var tmpTcIn = extractMediaInfo (listInfo[i].toString());
}
if (listInfo [i].toString().indexOf ("Duration") !=-1){
var tmpDuration = extractMediaInfo (listInfo[i].toString());
if (tmpDuration.toString().indexOf(" h") !=-1)
{
var tmpDurationh = tmpDuration.substring (0, tmpDuration.indexOf (" h"));
var tmpDurationmin =tmpDuration.substring (tmpDuration.indexOf ("h")+1, tmpDuration.indexOf ("min")-1);
var tmpDurationsec = tmpDuration.substring (tmpDuration.indexOf ("min")+4, tmpDuration.indexOf ("s")-1);
if (tmpDuration.toString().indexOf("ms") !=-1){
var tmpDurationcentsec = tmpDuration.substring (tmpDuration.indexOf ("s")+1, tmpDuration.indexOf ("ms")-1);
}
else {var tmpDurationcentsec = 0}
}
else if (tmpDuration.toString().indexOf(" min") !=-1)
{
var tmpDurationmin= tmpDuration.substring (0, tmpDuration.indexOf (" min"));
var tmpDurationsec = tmpDuration.substring (tmpDuration.indexOf ("min")+4, tmpDuration.indexOf ("s")-1);
var tmpDurationcentsec = tmpDuration.substring (tmpDuration.indexOf ("s")+1, tmpDuration.indexOf ("ms")-1);
if (tmpDuration.toString().indexOf("ms") !=-1){
var tmpDurationcentsec = tmpDuration.substring (tmpDuration.indexOf ("s")+1, tmpDuration.indexOf ("ms")-1);
}
else {var tmpDurationcentsec = 0}
}
else if (tmpDuration.toString().indexOf(" s") !=-1){
var tmpDurationsec = tmpDuration.substring (0, tmpDuration.indexOf (" s"));
if (tmpDuration.toString().indexOf("ms") !=-1){
var tmpDurationcentsec = tmpDuration.substring (tmpDuration.indexOf ("s")+1, tmpDuration.indexOf ("ms")-1);
}
else {var tmpDurationcentsec = 0}
}
else{
var tmpDurationsec = 0;
var tmpDurationcentsec = tmpDuration.substring (0, tmpDuration.indexOf ("ms")-1);
}
}
if ((i == (listInfo.length-1) || ( listInfo[i+1].toString().indexOf ("General") !=-1)) ){
media.duration =parseInt (tmpDurationh*media.frameRate*60*60) +parseInt (tmpDurationmin*media.frameRate*60) + parseInt( tmpDurationsec*media.frameRate) + parseFloat (tmpDurationcentsec*media.frameRate/100);
var timecodeGenericArray = [media.frameRate*60*60, media.frameRate*60,media.frameRate,1];
if (tmpTcIn)
{
var tmpArray = tmpTcIn.split (":");
media.tcIn =0;
for (var j =0; j<tmpArray.length; j++)
{
media.tcIn += parseInt (tmpArray[j] *timecodeGenericArray[j] );
}
media.tcOut = media.tcIn + media.duration;
}
}
}
return media
}
//Drop down lists (ddl)
function cleanDdl (ddl) {
for ( var i= ddl.items.length ; i >0 ; i--) {
ddl.remove (ddl.items[i]);
}
}
function updateDdlWithFolders (ddl) {
for(var i=1;i<=app.project.numItems; i++) {
if (app.project.item(i) instanceof FolderItem){
ddl.add("item", i+"."+ app.project.item(i).name);
}
}
ddl.slection = 0;
}
function updateDdlWithLayers (ddl) {
if (app.project.activeItem instanceof CompItem)
{
for(var i=1;i<=app.project.activeItem.numLayers; i++) {
ddl.add("item", i+"."+ app.project.activeItem.layer(i).name);
}
ddl.slection = 0;
}
}
function updateDdlWithNumLayers (ddl) {
if (app.project.activeItem instanceof CompItem) {
for(var i=1;i<=app.project.activeItem.numLayers; i++) {
ddl.add("item", i);
}
ddl.slection = 0;
}
}
function returnIndexFromddl (selection){
index = selection.toString().substr (0, selection.toString().indexOf("."));
return index;
}
//Effects management
function refreshDdls (digicutddl, LayerInddl, LayerOutddl){
cleanDdl (digicutddl) ;
cleanDdl (LayerInddl);
cleanDdl (LayerOutddl);
updateDdlWithLayers (digicutddl) ;
updateDdlWithNumLayers (LayerInddl);
updateDdlWithNumLayers (LayerOutddl);
}
function checkForInstalledEffect(fxName){
var effects = app.effects;
for (var i = 0; i < effects.length; i++){
if (effects[i].displayName === fxName.toString()){
return true;
}
}
return false;
}
function compareKeyTimes (keyA, keyB){
var comparison = 0;
if (keyA.timeKey> keyB.timeKey) {
comparison = 1;
} else if (keyA.timeKey < keyB.timeKey) {
comparison = -1;
}
return comparison;
}