Swapping First & Last Name in Title: NEW SCRIPT
Hello, script-heads!
That script in the previous thread to swap name-parts got bigger. This version has several (possible) improvements:
1. It looks for a likely divider between performer/creator name(s) and the rest of the filename.
They are "-", alt-26 (little right arrow), "in", "performing", and "perf." (with or without the period), or multiples of the symbols (--, for intance). You can add yours if it's not here.
1a. You can set whether you want to change the above connector, and if so, what you want the new one to be.
2. You can set the name connector (and, +, ++, &, etc) for multiple performer names. If you have several different ones in your filenames (or not), just set this to what you want it to be.
3. I realized that it is semi-standard to only reorder the first name to last, first, so the program does that by default. There's a setting to change that behavior, though. (NOTE: For some reason I don't understand, this only works on version 3.xx ARen. If you wan't to do that and don't have version 3.xx I recommend you go to Download and download v 3.95 portable now)
4. If you have performers with nicknames (Eric 'Slowhand' Clapton) and the nickname has some delimiter, like the apostrophe here, the script can't reorder the name. There is a variable, stripNicknameDelimiters, that can be set to "true", that will remove the delimiters so the names can be reordered. (This still only works on one-, two-, and three-word names though, so...
I think that's basically it. If your files don't have the performer first, followed by performance and other information, you will need to run it through a pre-processor batch first. If you can do that you should be able to get it back in the order you want after running this script; if you don't know how to do that and want to use this, just ask me.
NOTE: The first part of the script should be put in PRE-BATCH to improve performance on large file-sets. I've marked the spot. Here's the script:
// ----------------------------------------
// <DEFINABLE VALUES AND PRE-BATCH>:
// set a value for "and" (can be symbols [+, ++, etc] or
// letters or both.):
const newNameConnector = "and" ;
// Set testAllNames to true if you want to reorder
// all performer names, not just the first name (only works in v3.xx):
const testAllNames = false ;
// Set the following true if you want to strip nickname
// delimiters (', “”, `) so they reorder correctly:
const stripNicknameDelimiters = false ;
// The following is a regex defining possible connectors
// between performers and performances. If yours isn't
// here you'll need to add it in the parentheses using
// regex conventions. (The script won't handle spaces in
// your connector; you would have to take them out before
// running) :
const oldRemainderConnector = /\s+(performing|in|-|--|→|pe?rf\.?)+\s+/i ;
// If you want to standardize performer/performance
// connector, do it here. tfNewRemainderConnector =
// false, leaves old connectors; true standardizes.
// newRemainderConnector sets the new connector if
// applicable.
const tfNewRemainderConnector = false ;
const newRemainderConnector = "→ →" ; // <--- I used alt+26 space alt+26
// ----------------------------------------
// < ONLY CHANGE THE VALUES ABOVE! >
// ----------------------------------------
const newAnd = newNameConnector.replace( /^\s*(.*)\s*$/g, "$1" ) ;
const testAll = testAllNames ;
const stripNick = stripNicknameDelimiters ;
newRem = newRemainderConnector.replace( /^\s*(.*)\s*$/g, "$1" ) ;
const tfNRC = tfNewRemainderConnector ;
// -------------------------- The above can be moved to pre-batch
// -------------------------- for better performance on large file-sets
// NOTE: THIS SCRIPT DOESN'T CATCH NICKNAMES WITH DELIMITERS
// (like Orvon 'Gene' Autry, John “Bonzo” Bonham, Eric `Slowhand` Clapton)
// (The script won't freak out; it just won't rearrange those names).
// UNLESS YOU CHANGE stripNicknameDelimiters ABOVE, in which case the
// delimiters will be removed.
name = item.newBasename ;
workLen = name.search( oldRemainderConnector ) ;
oldRcPat = /\s+([^\s]+).*/
oldRC = name.slice( workLen, workLen + 15 ) ;
oldRem = oldRC.replace( oldRcPat, "$1" ) ;
wName = name.slice( 0, workLen ) ;
wName2 = wName ;
remainderName = name.slice( workLen + oldRem.length + 2 ) ;
if ( stripNick ) {
pattern = /['“”`\(\)]/g ;
wName2 = wName.replace( pattern, "" ) ;
wName = wName2 ;
}
// change any 2-3 word names before and/&
pattern = /^(\b([A-Za-z\-]+)\b\s+)?\b([^a&][A-Za-z\-]*)\b(\.?)\s+\b([A-Za-z\-]+)\b\s+(plus|and|&|\+)+\s+/gi ;
wName2 = wName.replace( pattern, "$5, $1 $3$4 " + newAnd + " " ) ;
wName = wName2 ;
if ( testAll ) {
// change 2-3 word names after and/&
pattern = /(plus|and|&|\+)+\s+(\b([A-Za-z\-]+)\b\s+)?\b([A-Za-z\-]+)\b(\.?)\s+\b([A-Za-z\-]+)\b\s{,5}/gi
wName = wName2.replace( pattern, newAnd+" $6, $3 $4$5 " ) ;
wName2 = wName ;
}
// change 2-3 word names with NO and/& (one person)
pattern = /^(\b([A-Za-z0]+)\b\s+)?\b([^a&][A-Za-z0]*)\b(\.?)\s+\b([A-Za-z0]+)\b\s*$/ ;
wName2 = wName.replace( pattern, "$5, $1 $3$4" ) ;
wName = wName2 ;
// Fix performer connector:
pattern = /\s+(plus|and|&|\+)+\s+/gi ;
wName2 = wName.replace( pattern, " "+newAnd+" " ) ;
wName = wName2 ;
// Reconnect performers with performances:
wName2 = wName + " " + ( tfNRC ? newRem : oldRem ) + " " +
remainderName ;
// Strip EXTRA spaces:
wName = wName2.replace( /\s+/g, " " ) ;
wName2 = wName ;
return wName ;
// ----------------------------------------
As always, use at your own discretion, and risk (and don't forget Undo Batch!).
Best,
DF
That script in the previous thread to swap name-parts got bigger. This version has several (possible) improvements:
1. It looks for a likely divider between performer/creator name(s) and the rest of the filename.
They are "-", alt-26 (little right arrow), "in", "performing", and "perf." (with or without the period), or multiples of the symbols (--, for intance). You can add yours if it's not here.
1a. You can set whether you want to change the above connector, and if so, what you want the new one to be.
2. You can set the name connector (and, +, ++, &, etc) for multiple performer names. If you have several different ones in your filenames (or not), just set this to what you want it to be.
3. I realized that it is semi-standard to only reorder the first name to last, first, so the program does that by default. There's a setting to change that behavior, though. (NOTE: For some reason I don't understand, this only works on version 3.xx ARen. If you wan't to do that and don't have version 3.xx I recommend you go to Download and download v 3.95 portable now)
4. If you have performers with nicknames (Eric 'Slowhand' Clapton) and the nickname has some delimiter, like the apostrophe here, the script can't reorder the name. There is a variable, stripNicknameDelimiters, that can be set to "true", that will remove the delimiters so the names can be reordered. (This still only works on one-, two-, and three-word names though, so...
I think that's basically it. If your files don't have the performer first, followed by performance and other information, you will need to run it through a pre-processor batch first. If you can do that you should be able to get it back in the order you want after running this script; if you don't know how to do that and want to use this, just ask me.
NOTE: The first part of the script should be put in PRE-BATCH to improve performance on large file-sets. I've marked the spot. Here's the script:
// ----------------------------------------
// <DEFINABLE VALUES AND PRE-BATCH>:
// set a value for "and" (can be symbols [+, ++, etc] or
// letters or both.):
const newNameConnector = "and" ;
// Set testAllNames to true if you want to reorder
// all performer names, not just the first name (only works in v3.xx):
const testAllNames = false ;
// Set the following true if you want to strip nickname
// delimiters (', “”, `) so they reorder correctly:
const stripNicknameDelimiters = false ;
// The following is a regex defining possible connectors
// between performers and performances. If yours isn't
// here you'll need to add it in the parentheses using
// regex conventions. (The script won't handle spaces in
// your connector; you would have to take them out before
// running) :
const oldRemainderConnector = /\s+(performing|in|-|--|→|pe?rf\.?)+\s+/i ;
// If you want to standardize performer/performance
// connector, do it here. tfNewRemainderConnector =
// false, leaves old connectors; true standardizes.
// newRemainderConnector sets the new connector if
// applicable.
const tfNewRemainderConnector = false ;
const newRemainderConnector = "→ →" ; // <--- I used alt+26 space alt+26
// ----------------------------------------
// < ONLY CHANGE THE VALUES ABOVE! >
// ----------------------------------------
const newAnd = newNameConnector.replace( /^\s*(.*)\s*$/g, "$1" ) ;
const testAll = testAllNames ;
const stripNick = stripNicknameDelimiters ;
newRem = newRemainderConnector.replace( /^\s*(.*)\s*$/g, "$1" ) ;
const tfNRC = tfNewRemainderConnector ;
// -------------------------- The above can be moved to pre-batch
// -------------------------- for better performance on large file-sets
// NOTE: THIS SCRIPT DOESN'T CATCH NICKNAMES WITH DELIMITERS
// (like Orvon 'Gene' Autry, John “Bonzo” Bonham, Eric `Slowhand` Clapton)
// (The script won't freak out; it just won't rearrange those names).
// UNLESS YOU CHANGE stripNicknameDelimiters ABOVE, in which case the
// delimiters will be removed.
name = item.newBasename ;
workLen = name.search( oldRemainderConnector ) ;
oldRcPat = /\s+([^\s]+).*/
oldRC = name.slice( workLen, workLen + 15 ) ;
oldRem = oldRC.replace( oldRcPat, "$1" ) ;
wName = name.slice( 0, workLen ) ;
wName2 = wName ;
remainderName = name.slice( workLen + oldRem.length + 2 ) ;
if ( stripNick ) {
pattern = /['“”`\(\)]/g ;
wName2 = wName.replace( pattern, "" ) ;
wName = wName2 ;
}
// change any 2-3 word names before and/&
pattern = /^(\b([A-Za-z\-]+)\b\s+)?\b([^a&][A-Za-z\-]*)\b(\.?)\s+\b([A-Za-z\-]+)\b\s+(plus|and|&|\+)+\s+/gi ;
wName2 = wName.replace( pattern, "$5, $1 $3$4 " + newAnd + " " ) ;
wName = wName2 ;
if ( testAll ) {
// change 2-3 word names after and/&
pattern = /(plus|and|&|\+)+\s+(\b([A-Za-z\-]+)\b\s+)?\b([A-Za-z\-]+)\b(\.?)\s+\b([A-Za-z\-]+)\b\s{,5}/gi
wName = wName2.replace( pattern, newAnd+" $6, $3 $4$5 " ) ;
wName2 = wName ;
}
// change 2-3 word names with NO and/& (one person)
pattern = /^(\b([A-Za-z0]+)\b\s+)?\b([^a&][A-Za-z0]*)\b(\.?)\s+\b([A-Za-z0]+)\b\s*$/ ;
wName2 = wName.replace( pattern, "$5, $1 $3$4" ) ;
wName = wName2 ;
// Fix performer connector:
pattern = /\s+(plus|and|&|\+)+\s+/gi ;
wName2 = wName.replace( pattern, " "+newAnd+" " ) ;
wName = wName2 ;
// Reconnect performers with performances:
wName2 = wName + " " + ( tfNRC ? newRem : oldRem ) + " " +
remainderName ;
// Strip EXTRA spaces:
wName = wName2.replace( /\s+/g, " " ) ;
wName2 = wName ;
return wName ;
// ----------------------------------------
As always, use at your own discretion, and risk (and don't forget Undo Batch!).
Best,
DF