Tag math

Advanced Renamer forum
#1 : 31/10-21 19:06
Alan Reed
Alan Reed
Posts: 3
Can I add a number to a tag value

As in "<Video Date Hour>+1" so I could adjust values of the tags when composing filename?

Thanks if you can answer this :)


31/10-21 19:06
#2 : 02/11-21 11:20
David Lee
David Lee
Posts: 1125
A simple solution is to insert the Hour tag as normal then add 1 using a Renumber method.

However you will run into problems if this takes you beyond midnight - which would lead to a value of 25.

You can use a Script method to get round this issue:
hour = parseInt(app.parseTags("<Video Date Hour>")) +1;
if (hour == 25) hour = 1;
hour = ("0" + hour).slice(-2);

However if you are inserting more than just the hour then you will also need to increment the day, possibly the month and maybe even the year!

A better scripting solution is to parse the date/time into a Unix epoch datestamp add 3600000 milliseconds then extract the hour using getUTCHours.

See my post in thread www.advancedrenamer.com/forum_thread?forum_id=11037 for an example of changing a timezone by +7 hours. You will need to extract the full timedate abd modify the regular expression appropriately and use the getUTC... versions of the date/time methods to avoid erroneous application of daylight saving.




02/11-21 11:20 - edited 02/11-21 12:22
#3 : 03/11-21 16:34
Alan Reed
Alan Reed
Posts: 3
Reply to #2:
The simple solution was all that was needed - thank you very much for your help.

I'm kicking myself I never though of that additional Method to tweak the hour value.

I sort of barely understand the more comprehensive solutions you offered but would ask if they were necessary but thanks nevertheless thanks for the insight as to how powerful AR can be.

Regards
Alan.


03/11-21 16:34
#4 : 05/04-22 14:51
KM
KM
Posts: 1
Reply to #2:

Hi. I would like to rename my video file to include the date/time from 2017:07:22 03:29:17 to 2017:07:21 18:35:17 (GMT+8). I found this thread, which mentions www.advancedrenamer.com/forum_thread?forum_id=11037. I don't know anything about scripting, and it looks like alien to me. This is what I did.

Step 1, I copied and paste this to the scripting window...

match = item.name.match(/^(.*_)(\d{4}-\d{2}-\d{2})_(\d{2})-(\d{2})-(\d{2})$/);
epoch = Date.parse(match[2] + 'T' + match[3] + ':' + match[4] + ':' + match[5]);
date = new Date(epoch + 7 * 3600000);
return match[1]
+ date.getFullYear()
+ "-" + ("0" + (date.getMonth() + 1)).slice(-2)
+ "-" + ("0" + date.getDate()).slice(-2)
+ "_" + ("0" + date.getHours()).slice(-2)
+ "-" + ("0" + date.getMinutes()).slice(-2)
+ "-" + ("0" + date.getSeconds()).slice(-2);

Step 2, I clicked on the "apply script"...
In the error column, it said "Invalid script: Invalid input pre script: uncaught: 'Invalid return (line 4)'"

Would anyone be kind enough to show me a dummies 101 kind of step by step execution so I can rename my files accordingly?

Also, media files have tons of date reference, currently I have in the New Name Method <Video Date Year:0000><Video Date Month:00><Video Date Day:00>_<Video Date Hour:00><Video Date Min:00><Video Date Sec:00>_<Incr Nr>



05/04-22 14:51 - edited 05/04-22 14:57
#5 : 06/04-22 09:34
David Lee
David Lee
Posts: 1125
Reply to #4:
KM:

Your post does not make any sense. Please explain exactly what you are trying to do and give examples of existing and target filenames.

I expect that the code you have copied from an unrelated thread probably will not be appropriate for your problem. However the error message indicates that you have pasted the code into the Pre-batch script instead of the main script window.

Try reading the User Guide introduction to scripting.


06/04-22 09:34