Rename JPGs differently based on EXIF model name

Advanced Renamer forum
#1 : 30/12-21 20:14
DarrenD108
DarrenD108
Posts: 2
I have 3 phones/cameras that have different naming conventions that I would like to maintain.
I have recovered some deleted photos but the filenames are mangled so I want to put them back to the filenames that the phones/cameras would have given them.
One phone uses IMG_yyyymmdd_hhmmssSSS.jpg (SSS is subseconds)
Another phone uses yyyymmdd_hhmmss.jpg

If I load all .JPG files into AdvancedRenamer can I run a script that checks the EXIF model name and if model == "Phone1" then rename with "IMG_" + some EXIF variables and if model == "Phone2" then rename with some EXIF variables

I tried using the Script "apply to Name" with name collision rule "Fail" without any EXIF model checks (as a minimal test to rename files) but no matter what I put in the script "return XXXX;" it would not rename anything (the "New Filename" was in grey and always the same as "Filename").

I am clearly missing something, can someone help please?

I am using AdvancedRenamer 3.88 on Windows 10 x64

Thanks
Darren


30/12-21 20:14
#2 : 03/01-22 15:35
DarrenD108
DarrenD108
Posts: 2
Reply to #1:
I managed to finally write a script that did what I want. In case anyone else reads this post because they have the same issue I will include the script that worked for me. It ain't pretty but worked enough for me to do what I wanted. Hopefully you could adapt it to suit your exact needs.

I actually wrote 2 scripts, one for MP4 videos and one for JPG pictures.



//--------------------------------------------------------------------------------------------------------
// Rename MP4 files
//--------------------------------------------------------------------------------------------------------
date = "yyyymmdd";
time = "hhmmss";

// This script only renames MP4 files
if (item.extension != ".mp4") return (item.name);

model = item.exifToolValue("AndroidModel");
author = item.exifToolValue("Author");
compressor = item.exifToolValue("CompressorName");
androidVersion = item.exifToolValue("AndroidVersion");
playMode = item.exifToolValue("PlayMode");
majorBrand = item.exifToolValue("MajorBrand");
handlerVendorID = item.exifToolValue("HandlerVendorID");
handlerDescription = item.exifToolValue("HandlerDescription");

if (model == "moto g(8) power")
{
// Use MediaCreateDate - it isn't correct, but it's the best we've got
datetime = item.exifToolValue("MediaCreateDate").replace(/:/g, "").replace(/ /g, "_");
name = "VID_" + datetime + "000";
}
else if (compressor == "MOTO")
{
if (majorBrand == "MP4 Base Media v1 [IS0 14496-12:2003]")
{
model = "MotoG1";

// Use MediaCreateDate - it isn't correct, but it's the best we've got
datetime = item.exifToolValue("MediaCreateDate").replace(/:/g, "").replace(/ /g, "_");
name = "VID_" + datetime + "000";
}
else if ((androidVersion == "6.0") || (androidVersion == "6.0.1"))
{
model = "MotoG3";

// Use FileModifyDate - it isn't correct, but it's the best we've got
// FileModifyDate was shown to have local time when in Thailand but all others were UK time (UTC)
datetime = item.exifToolValue("FileModifyDate").replace(/:/g, "").replace(/ /g, "_");
// Strip off delta time (seen in Thailand videos) - note ":" already removed
datetime = datetime.replace("+0000","");
// Use MediaCreateDate - it isn't correct, but it's the best we've got
datetime = item.exifToolValue("MediaCreateDate").replace(/:/g, "").replace(/ /g, "_");
name = "VID_" + datetime + "000";
}
else
{
model = "MotoG3-possibly";

// Use FileModifyDate - it isn't correct, but it's the best we've got
// FileModifyDate was shown to have local time when in Thailand but all others were UK time (UTC)
datetime = item.exifToolValue("FileModifyDate").replace(/:/g, "").replace(/ /g, "_");
// Strip off delta time (seen in Thailand videos) - note ":" already removed
datetime = datetime.replace("+0000","");
name = "VID_" + datetime + "000";
}
}
else if (handlerVendorID == "Apple")
{
model = "Apple_download";

// Use MediaCreateDate - it isn't correct, but it's the best we've got
datetime = item.exifToolValue("MediaCreateDate").replace(/:/g, "").replace(/ /g, "_");
name = "download_" + datetime;
}
else if (handlerDescription.includes("IsoMedia File Produced by Google"))
{
model = "Google_download";

// Use MediaCreateDate - it isn't correct, but it's the best we've got
datetime = item.exifToolValue("MediaCreateDate").replace(/:/g, "").replace(/ /g, "_");
name = "download_" + datetime;
}
else if (author == "LGE/")
{
model = "LG-H815_guess";

// Use MediaCreateDate - it isn't correct, but it's the best we've got
datetime = item.exifToolValue("MediaCreateDate").replace(/:/g, "").replace(/ /g, "_");
name = "VID_" + datetime;
}
else if (author == "LG-H870/")
{
model = "LG-H870";

// Use MediaCreateDate - it isn't correct, but it's the best we've got
datetime = item.exifToolValue("MediaCreateDate").replace(/:/g, "").replace(/ /g, "_");
name = "VID_" + datetime;
}
else if (playMode == "SEQ_PLAY")
{
model = "audio_recording_";

// Use MediaCreateDate - it isn't correct, but it's the best we've got
datetime = item.exifToolValue("MediaCreateDate").replace(/:/g, "").replace(/ /g, "_");
name = "VID_" + datetime;
}
else
{
// Unexpected model (or no model)

if (model == "")
{
model = "UNKNOWN"
}
model = "___UNHANDLED_" + model

datetime = item.exifToolValue("DateTimeOriginal").replace(/:/g, "").replace(/ /g, "_");
if (datetime != "")
{
// DateTimeOriginal worked so use that
name = model + "_" + datetime;
}
else
{
datetime = item.exifToolValue("CreateDate").replace(/:/g, "").replace(/ /g, "_");
if (datetime != "")
{
// CreateDate worked so use that
name = model + "_" + datetime;
}
else
{
datetime = item.exifToolValue("ModifyDate").replace(/:/g, "").replace(/ /g, "_");
if (datetime != "")
{
// ModifyDate worked so use that
name = model + "_" + datetime;
}
else
{
// Really don't know what this is
name = model + "_no_idea_what_this_is_" + item.newBasename;
}
}
}
}

// For debug
name = model.replace("/","") + "_" + name;

return name;

















//--------------------------------------------------------------------------------------------------------
// Rename JPG files
//--------------------------------------------------------------------------------------------------------
date = "yyyymmdd";
time = "hhmmss";

// This script only renames JPG files
if (item.extension != ".jpg") return (item.name);

model = item.exifToolValue("Model");
if ( (model == "SM-N960F")
|| (model == "GT-N7100")
|| (model == "LG-H815")
|| (model == "LG-H870")
)
{
// These models always uses DateTimeOriginal
datetime = item.exifToolValue("DateTimeOriginal").replace(/:/g, "").replace(/ /g, "_");
name = datetime;
}
else if ( (model == "Nexus 10")
|| (model == "GT-I9100")
|| (model == "FinePix JX530")
)
{
// These models PROBABLY use DateTimeOriginal
// Couldn't find original photos to confirm
datetime = item.exifToolValue("DateTimeOriginal").replace(/:/g, "").replace(/ /g, "_");
name = datetime;
}
else if (model == "moto g(8) power")
{
// Motorola G8 Power seems to use GPSTimeStamp
// DateTimeOriginal seems to be a second or so later than the filename
date = item.exifToolValue("GPSDateStamp").replace(/:/g, "");
time = item.exifToolValue("GPSTimeStamp").replace(/:/g, "");
datetime = date + "_" + time;
if (date == "")
{
// No GPS data so use the DateTimeOriginal - it's not correct but it's the best we've got
datetime = item.exifToolValue("DateTimeOriginal").replace(/:/g, "").replace(/ /g, "_");
}
// Add default SSS subseconds value - the EXIF value is not what is used for the filename
name = datetime + "000";
}
else if (model == "MotoG3")
{
// Motorola G3 always uses DateTimeOriginal
datetime = item.exifToolValue("DateTimeOriginal").replace(/:/g, "").replace(/ /g, "_");
// Add default SSS subseconds value - the EXIF value is not what is used for the filename
name = datetime + "000";
}
else
{
// Unexpected model (or no model)

if (model == "")
{
model = "UNKNOWN"
}
model = "___UNHANDLED_" + model

datetime = item.exifToolValue("DateTimeOriginal").replace(/:/g, "").replace(/ /g, "_");
if (datetime != "")
{
// DateTimeOriginal worked so use that
name = model + "_" + datetime;
}
else
{
datetime = item.exifToolValue("CreateDate").replace(/:/g, "").replace(/ /g, "_");
if (datetime != "")
{
// CreateDate worked so use that
name = model + "_" + datetime;
}
else
{
datetime = item.exifToolValue("ModifyDate").replace(/:/g, "").replace(/ /g, "_");
if (datetime != "")
{
// ModifyDate worked so use that
name = model + "_" + datetime;
}
else
{
// Really don't know what this is
name = model + "_no_idea_what_this_is_" + item.newBasename;
}
}
}
}

// For debug
name = model + "_" + name;

return name;


03/01-22 15:35