Sharing my video renaming script using the MediaCreateDate tag

Advanced Renamer forum
#1 : 08/08-16 07:15
Nic Harding
Nic Harding
Posts: 1
I use the following script when renaming my video files that come from my Galaxy S7. When they get copied from my phone all the file dates are set to the day when I copied them. Hope it helps someone!


// Extract the date and time info from the 'MediaCreateDate' tag
var mcdText = app.parseTags('<ExifTool:MediaCreateDate>');
var mcdYear = mcdText.substring(0, 4);
var mcdMonth = mcdText.substring(5, 7);
var mcdDay = mcdText.substring(8, 10);
var mcdHour = mcdText.substring(11, 13);
var mcdMinute = mcdText.substring(14, 16);
var mcdSecond = mcdText.substring(17, 19);

// http://www.w3schools.com/Js/js_date_formats.asp
// Format date string using the javascript date format (YYYY-MM-DDTHH:MM:SS)
// The T in the date string, between the date and time, indicates UTC time.
var FormattedDate = mcdYear + "-" + mcdMonth + "-" + mcdDay + "T" + mcdHour + ":" + mcdMinute + ":" + mcdSecond;

// Create a date object based on 'FormattedDate'
var mcdDate = new Date(FormattedDate);

// Extract GMT hour and minutes from 'FileModifyDate'
var fmdText = app.parseTags('<ExifTool:FileModifyDate>');
var GMT = fmdText.split("+").pop(); // Grab data from after the + char.
var GMTsplit = GMT.split("_"); // Seperate the hour and minute parts
var GMThour = Number(GMTsplit[0]); // Number() removes leading 0
var GMTmin = Number(GMTsplit[1]); // Number() removes leading 0

// http://www.javascriptcookbook.com/article/Perfo rm-date-manipulations-based-on-adding-or -subtracting-time/
// Add/Subtract GMT time from the 'MediaCreateDate' time (which has no GMT data!)
// Only adding at the moment (For + time zones)
// Have to look at using getTimezoneOffset()
mcdDate.setHours(mcdDate.getHours() + GMThour); // Only adding at the moment
mcdDate.setMinutes(mcdDate.getMinutes() + GMTmin); // Only adding at the moment

// Forming the renamed filename adding leading '0's to month,day,hour,min,second.
var date = mcdDate.getFullYear()+' '+("0" + (mcdDate.getMonth() + 1)).slice(-2)+' '+mcdDate.getDate()
var time = ('0' + mcdDate.getHours()).slice(-2)+'-'+('0' + mcdDate.getMinutes()).slice(-2)+'-'+('0' + mcdDate.getSeconds()).slice(-2);
var filename = date+' '+time+' - video_name';

return filename;


08/08-16 07:15 - edited 08/08-16 07:25
#2 : 09/12-16 17:59
Karl Hiller
Karl Hiller
Posts: 1
THANK YOU! That is exactly the thing I needed to fix the ridiculous renaming 'feature' on the S7. I don't have the scripting skills to write that myself but I was able to tweak and use it with a little bit of effort.

I took out the GMT extraction and manually entered the offset because I almost never leave my time zone. And I had no problem with a negative offset. So that line became

mcdDate.setHours(mcdDate.getHours() - 5);

Thanks again, you have made my life a lot easier and my video file sorting a lot more accurate.

Karl


09/12-16 17:59