if(item.gpsExists == true) No Longer Working in v3.86?

Advanced Renamer forum
#1 : 23/09-20 21:30
Matt Gorner
Matt Gorner
Posts: 6
I have a script that checks for GPS EXIF data so that the location can be part of the filename.

On the latest photo import AR v3.85 finds the GPS info, whereas AR v3.86 always returns false using this check:

if(item.gpsExists == true)

Did something change with the new JavaScript engine?

Cheers
Matt


23/09-20 21:30
#2 : 24/09-20 18:55
Tobi
Tobi
Posts: 8
Reply to #1:

Hi there,
since v3.86 some script not work



NOT WORKING:

if(item.gpsExists == true)
if(item.gpsExists == false)
if(item.gpsExists == 0)
if(item.gpsExists != 0)

WORKING:

if(item.gpsExists === undefined)
if(item.gpsExists !== undefined)

This is working for me and all variables, maybe someone can tell my why?


24/09-20 18:55
#3 : 25/09-20 02:22
Matt Gorner
Matt Gorner
Posts: 6
Reply to #2:

Hi Tobi

Maybe the new engine is more strict?

== Converts the variable values to the same type before performing comparison.

Whereas:

=== Does not do any type conversion and returns true only if both values and types are identical

But I'm not aware of == being depreciated so I can only presume it's a bug.


25/09-20 02:22
#4 : 25/09-20 11:45
David Lee
David Lee
Posts: 1125
Reply to #3:
Version 3.86 appears to be riddled with "issues" that are inconsistent with previous versions - best advice probably is to revert to version 3.85.


25/09-20 11:45
#5 : 25/09-20 12:45
Kim Jensen
Kim Jensen
Administrator
Posts: 880
Because of the big change in JS support, there can be various incompatibilities with the scripts made with a previous version. Please let me know your findings and I will try to find fixes for them for an upcoming release in a couple of weeks.


25/09-20 12:45
#6 : 26/09-20 15:53
Tobi
Tobi
Posts: 8
Reply to #5:
I have also a problem to start JS Scripts in AR 3.86...
So i create a .aren file with a script and save it.

After that i close all windows, open my .aren again, add file for renaming with drag and drop...
^^ sometimes working
sometimes i had to close and open AR 3.86 more time than it works...

When i add more than 2 r 3 files for renaming, t is even more difficult to get a result.

AR 3.85 work stable with the same .aren file and script.

JS engine is buggy!?


26/09-20 15:53 - edited 26/09-20 15:54
#7 : 27/09-20 20:35
Kim Jensen
Kim Jensen
Administrator
Posts: 880
Reply to #6:
If you have a script that is not working as expected, please sent it to me. I also need to know how many files you have in the list and what type of file they are.


27/09-20 20:35
#8 : 29/09-20 11:23
Tobi
Tobi
Posts: 8
Reply to #7:

This Script add on the end of movie-filename --- [definition format codec minutes]
like:
mymovie --- [4K 2160p H264 - 25 min].mp4

for example (this work perfect in AR 3.85 and sometimes in AR 3.86):
############################################################
var format;
var codec;
var definition;
var hour;
var minutes;
var min;
var m;
var s;
var h;
// Auflösungen:
// VGA 640 x 480
// Standard Definition PAL-D (SD) 720 × 576
// High Definition (HD) 1280 x 720
// Full High Definition (HD) 1920 × 1080
// Quad HD (QHD) 2560 x 1440
// Ultra High Definition (UHD) 3840 × 2160
// 4K (UHD) 4096 × 2160
// UHD-2 (UHD2) 7680 × 4320
// 8K Full Format (UHD2) 8192 × 4320
if (app.parseTags("<Video Width>") !== undefined && app.parseTags("<Video Width>").length > 0) {
if (app.parseTags("<Video Width>") >= 8192 || app.parseTags("<Video Height>") >= 4320) {
format = '4320p';
definition = '8K';
}
else if (app.parseTags("<Video Width>") >= 7680 || app.parseTags("<Video Height>") >= 4320) {
format = '4320p';
definition = 'UHD2';
}
else if (app.parseTags("<Video Width>") >= 4096 || app.parseTags("<Video Height>") >= 2160) {
format = '2160p';
definition = '4K';
}
else if (app.parseTags("<Video Width>") >= 3840 || app.parseTags("<Video Height>") >= 2160) {
format = '2160p';
definition = "UHD";
}
else if (app.parseTags("<Video Width>") >= 2560 || app.parseTags("<Video Height>") >= 1440) {
format = '1440p';
definition = "QHD";
}
else if (app.parseTags("<Video Width>") >= 1920 || app.parseTags("<Video Height>") >= 1080) {
format = '1080p';
definition = 'HD';
}
else if (app.parseTags("<Video Width>") >= 1280 || app.parseTags("<Video Height>") >= 720) {
format = '720p';
definition = 'HD';
}
else if (app.parseTags("<Video Width>") >= 720 || app.parseTags("<Video Height>") >= 576) {
format = 'PAL-SECAM';
definition = 'SD';
}
else if (app.parseTags("<Video Width>") >= 640 || app.parseTags("<Video Height>") >= 480) {
format = 'NTSC';
definition = 'SD';
}
}
if (format === undefined) {
if (item.exifToolValue("ImageWidth") !== undefined && item.exifToolValue("ImageWidth").length > 0) {
if (item.exifToolValue("ImageWidth") >= 8192 || item.exifToolValue("ImageHeight") >= 4320) {
format = '4320p';
definition = '8K';
}
else if (item.exifToolValue("ImageWidth") >= 7680 || item.exifToolValue("ImageHeight") >= 4320) {
format = '4320p';
definition = 'UHD2';
}
else if (item.exifToolValue("ImageWidth") >= 4096 || item.exifToolValue("ImageHeight") >= 2160) {
format = '2160p';
definition = '4K';
}
else if (item.exifToolValue("ImageWidth") >= 3840 || item.exifToolValue("ImageHeight") >= 2160) {
format = '2160p';
definition = "UHD";
}
else if (item.exifToolValue("ImageWidth") >= 2560 || item.exifToolValue("ImageHeight") >= 1440) {
format = '1440p';
definition = "QHD";
}
else if (item.exifToolValue("ImageWidth") >= 1920 || item.exifToolValue("ImageHeight") >= 1080) {
format = '1080p';
definition = 'HD';
}
else if (item.exifToolValue("ImageWidth") >= 1280 || item.exifToolValue("ImageHeight") >= 720) {
format = '720p';
definition = 'HD';
}
else if (item.exifToolValue("ImageWidth") >= 720 || item.exifToolValue("ImageHeight") >= 576) {
format = 'PAL-SECAM';
definition = 'SD';
}
else if (item.exifToolValue("ImageWidth") >= 640 || item.exifToolValue("ImageHeight") >= 480) {
format = 'NTSC';
definition = 'SD';
}
}
}
if (format === undefined) {
if (item.exifToolValue("SourceImageWidth") !== undefined && item.exifToolValue("SourceImageWidth").length > 0) {
if (item.exifToolValue("SourceImageWidth") >= 8192 || item.exifToolValue("SourceImageHeight") >= 4320) {
format = '4320p';
definition = '8K';
}
else if (item.exifToolValue("SourceImageWidth") >= 7680 || item.exifToolValue("SourceImageHeight") >= 4320) {
format = '4320p';
definition = 'UHD2';
}
else if (item.exifToolValue("SourceImageWidth") >= 4096 || item.exifToolValue("SourceImageHeight") >= 2160) {
format = '2160p';
definition = '4K';
}
else if (item.exifToolValue("SourceImageWidth") >= 3840 || item.exifToolValue("SourceImageHeight") >= 2160) {
format = '2160p';
definition = "UHD";
}
else if (item.exifToolValue("SourceImageWidth") >= 2560 || item.exifToolValue("SourceImageHeight") >= 1440) {
format = '1440p';
definition = "QHD";
}
else if (item.exifToolValue("SourceImageWidth") >= 1920 || item.exifToolValue("SourceImageHeight") >= 1080) {
format = '1080p';
definition = 'HD';
}
else if (item.exifToolValue("SourceImageWidth") >= 1280 || item.exifToolValue("SourceImageHeight") >= 720) {
format = '720p';
definition = 'HD';
}
else if (item.exifToolValue("SourceImageWidth") >= 720 || item.exifToolValue("SourceImageHeight") >= 576) {
format = 'PAL-SECAM';
definition = 'SD';
}
else if (item.exifToolValue("SourceImageWidth") >= 640 || item.exifToolValue("SourceImageHeight") >= 480) {
format = 'NTSC';
definition = 'SD';
}
}
}
if (app.parseTags("<Video Codec>") !== undefined && app.parseTags("<Video Codec>").length > 0) {
if (app.parseTags("<Video Codec>").match("AVC")) {
codec = 'H264';
}
else if (app.parseTags("<Video Codec>").match("HEVC")) {
codec = 'HEVC H265';
}
else {
codec = app.parseTags("<Video Codec>");
}
}
if (codec === undefined) {
if (item.exifToolValue("VideoCodecID") !== undefined && item.exifToolValue("VideoCodecID").length > 0) {
if (item.exifToolValue("VideoCodecID").match("AVC")) {
codec = 'H264';
}
else if (item.exifToolValue("VideoCodecID").match("HEVC")) {
codec = 'HEVC H265';
}
else {
codec = item.exifToolValue("VideoCodecID");
}
}
else if (item.exifToolValue("CompressorID") !== undefined && item.exifToolValue("CompressorID").length > 0) {
if (item.exifToolValue("CompressorID").match("avc1")) {
codec = 'H264';
}
else if (item.exifToolValue("CompressorID").match("hvc1")) {
codec = 'HEVC H265';
}
else {
codec = item.exifToolValue("CompressorID");
}
}
else if (item.exifToolValue("CompatibleBrands") !== undefined && item.exifToolValue("CompatibleBrands").length > 0) {
if (item.exifToolValue("CompatibleBrands").match("avc1")) {
codec = 'H264';
}
else if (item.exifToolValue("CompatibleBrands").match("hvc1")) {
codec = 'HEVC H265';
}
else {
codec = item.exifToolValue("CompatibleBrands");
}
}
}
if (app.parseTags("<Video Duration>") !== undefined && app.parseTags("<Video Duration>").length > 0) {
if (app.parseTags("<Video Min>") !== undefined && app.parseTags("<Video Min>").length > 0) {
if (app.parseTags("<Video Hour>") !== undefined && app.parseTags("<Video Hour>").length > 0) {
hour = +app.parseTags("<Video Hour>");
hour = hour + 'h,';
h = +app.parseTags("<Video Hour>") * 60;
m = +h + +app.parseTags("<Video Min>");
}
else {
m = +app.parseTags("<Video Min>");
}
s = Math.round(app.parseTags("<Video Sec>") / 60);
m = +m + +s;
min = +app.parseTags("<Video Min>") + +s;
minutes = m + ' min';
}
}
if (min === undefined) {
if (item.exifToolValue("ImageWidth") !== undefined && item.exifToolValue("ImageWidth").length > 0) {
if (item.exifToolValue("Duration") !== undefined && item.exifToolValue("Duration").length > 0) {
var a = item.exifToolValue("Duration").split(':');
if (a[1] != undefined) {
if (a[0] != '0') {
hour = +a[0];
hour = hour + 'h,';
h = +a[0] * 60;
m = +h + +a[1];
}
else {
m = +a[1];
}
s = Math.round(+a[2] / 60);
m = +m + +s;
min = +a[1] + +s;
minutes = m + ' min';
}
}
}
}
return item.newBasename + ' --- [' + definition + ' ' + format + ' ' + codec + ' - ' + minutes + ']';
############################################################

it's not important how many files...
in AR 3.85 i get a jscript error if i use to many files (between 10-20) sometimes more...
in AR 3.86 no error message and also no result but sometimes after reload (auto test) is working...


29/09-20 11:23 - edited 29/09-20 11:25
#9 : 29/09-20 20:37
Kim Jensen
Kim Jensen
Administrator
Posts: 880
Reply to #8:
My guess is that your script is too slow. The program will only let the script run for a certain amount of time. Slow scripts will timeout the execution. Everytime the JS script calls a native Advanced Renamer method, like parseTags or exifToolValue, the program will switch context from the JS execution to native program execution and then back again. This is a heavy operation and should be minimized as much as possible. In the worst case you are calling parseTags and exifToolValue 97 times for each file in the list. This can be reduced drasticly by storing the value in a variable.

Instead of
if (app.parseTags("<Video Width>") !== undefined && app.parseTags("<Video Width>").length > 0) {

do this. Note, no need to check for undefined. parseTags will always return a string.
var videoWidth = app.parseTags("<Video Width>");
if (videoWidth.length > 0) {

or this, which is even faster. Note, item.videoWidth is always an integer.
var videoWidth = item.videoWidth;
if (videoWidth > 0) {



29/09-20 20:37
#10 : 03/10-20 13:54
Tobi
Tobi
Posts: 8
Reply to #9:

the "!== undefined" i do for AR 3.86 only

so that mean i should split the script in a few parts?


03/10-20 13:54
#11 : 27/10-20 20:43
John Smith
John Smith
Posts: 4
Tnx!


27/10-20 20:43