Just for Fun – an Impossible Task – Append Initials of Song

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Just for Fun – an Impossible Task – Append Initials of Song

Postby trm2 » Wed Feb 12, 2020 2:31 pm

Here's a challenge (taken from upcoming Volume II) that I need help on.. I would like to include alternatives
to my failed attempt and maybe even using BRC (Bru are you listening) or JavaScript (Admin - up to a challenge)?

So here it is:

-------------------------

Just for Fun – an Impossible Task – Append Initials of Song Title to end of Filename


Perhaps this can be done in Javascript – but not in RegEx as far as I can tell. But here it is anyway. I thought I would
give it a try since it was similar to another challenge I did:

Sample:

SunFly116_12-The Beatles- I Want To Hold Your Hand.mkv to SunFly116_12-The Beatles- I Want To Hold Your Hand-IWTHYH.mkv

Observation:

1. Impossible – Yes I think so. Any challengers out there who can do better? Post it in the forum.
2. The Poster wants to take each initial from each word that makes up the song title and append this to the end of the
same filename.

Why impossible?

1. Unknown variables of how many words will make up the title. No pattern.

2. Only have 9 Capture Groups available.

3. After taking each initial and reached EOF, I cannot in my experience think of how to backtrack enough to capture the
last part of the string when the expression has already been satisfied.

So for S&** and Giggles I base my RegEx on the only (Thank God) sample given.

It is not correct because, although my results are good, they remain incomplete. I am only able to append to the end of
the first part of the filename.

TaDah!

Match: (.*)-*- ([A-Z]).+?([A-Z]).+?([A-Z]).+?([A-Z]).+?([A-Z]).+?([A-Z])(.*)
Replace: \1-\2\3\4\5\6\7

Final Note:
This is so limited it can only be matched with a filename that has exactly 6 words in the title.

------------------------------

So there you have it - my failed attempt - so limited, so restrictive and not even the full solution. I require
successful solutions and much more universal than the solution limited to 6 words in the title.

Personally I think BRC can handle it because it can handle multiple RegEx's so more than 6 words should be no problem. JavaScript
could also handle it - but I would like to see successful BRU RegEx's as well that would allow me to exclaim happily, 'I was Wrong' when I stated
emphatically that it was impossible to do it in BRU.

Also you must provide that your solution works on more than just the single sample I have here.

Thanks in advance and let the challenge begin.
trm2
 
Posts: 156
Joined: Wed Jan 15, 2020 12:47 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby bru » Wed Feb 12, 2020 7:46 pm

The problem is there's no way for BRC/BRU to know where the SongName begins.
IF you're saying that a final - always preceeds SongName (no dashes in SongName), you could:

@echo on
cd/d "FolderPathToYour.mkv's"
set reg1=/Regexp:"^(.*- *.*?)([A-Z])([^-]+[^A-Z])$:\1\2|\3-\2"
set reg2=/Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3"
set max10=%reg2% %reg2% %reg2% %reg2% %reg2% %reg2% %reg2% %reg2% %reg2%
brc32 /Pattern:*mkv %reg1% %max10% /ReplaceCI:"|": /Execute
pause>nul

Results:
SunFly116_12-The Beatles- I Want To Hold Your Hand.mkv ---> SunFly116_12-The Beatles- I Want To Hold Your Hand-IWTHYH.mkv

That would handle up to 10 words in SongName, you could always add more %reg2%'s if needed.
Reg1 is written to purposely not match files ending with Uppercase (assumes previously renamed).
If you want a single command for testing, go to the folder with your .mkvs, launch a command-prompt & copy this:
Code: Select all
brc64 /Pattern:*mkv /Regexp:"^(.*- *.*?)([A-Z])([^-]+[^A-Z])$:\1\2|\3-\2" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3" /Regexp:"(.*[|])([^|]*?)([A-Z])([^|]*)(-[A-Z]+)$:\1\2\3|\4\5\3"  /ReplaceCI:"|":


If you dont keep brc64 within 1 of your system's %PATH% folders, you'll need to spec the "FullPathTo\brc64" (versus just brc64).
The /Execute has been stripped to let you preview the would-be rename(s).
Good luck copying it though, my browser always seem to fail.
bru
 
Posts: 62
Joined: Wed Jan 31, 2018 7:35 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby bru » Wed Feb 12, 2020 8:52 pm

You might wanna turn that @echo off though, lol.
bru
 
Posts: 62
Joined: Wed Jan 31, 2018 7:35 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby Admin » Thu Feb 13, 2020 5:44 am

If the title where the initials are to be taken from it is always after the -, then in Javascript:
a) get part of the name after the -
b) split into an array of words
c) append first letter of of each word to name (captialized if needed)
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby trm2 » Thu Feb 13, 2020 2:20 pm

Thank you for that Admin, but for those that do not know JavaScript, such as I, we need your script..
a nice explanation of the array would also be appreciated.

Thanks in advance.
trm2
 
Posts: 156
Joined: Wed Jan 15, 2020 12:47 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby trm2 » Thu Feb 13, 2020 7:47 pm

Bru,

Your code - both of them, have been tested successfully and added to the volume. Any other comments- such as a full analysis
of your work would be appreciated and could help others.

Thanks again.
trm2
 
Posts: 156
Joined: Wed Jan 15, 2020 12:47 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby Admin » Fri Feb 14, 2020 12:54 am

Code: Select all
function getSecondPart(str) {
   return str.substr(str.lastIndexOf("-")+1);
}

function getFirstPart(str) {
   return str.substr(0,str.lastIndexOf("-"));
}

var title = getSecondPart(name);
words = title.split(' ');
var text = "";

for (var i = 0; i < words.length; i++) {
   text += words[i].substr(0,1);
}

newName = getFirstPart(name) + "-" + getSecondPart(name) + "-" + text;
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby trm2 » Fri Feb 14, 2020 2:05 am

Thank you Admin.


Two successes - BRC by Bru and JavaScript by Admin

That leaves only one more test - IN BRU RegEX - the one I couldn't get right. Any takers to prove me wrong?
- Or did I successfully exhaust all possibilities?

Using my RegEx:

Match: (.*)-*- ([A-Z]).+?([A-Z]).+?([A-Z]).+?([A-Z]).+?([A-Z]).+?([A-Z])(.*)
Replace: \1-\2\3\4\5\6\7

I was only able to come up with this:

SunFly116_12-The Beatles-IWTHYH.mkv


I think it is impossible to do in one single RegEx - so prove me wrong. Even provide alternatives using the other sections with RegEx.

any more takers??

PS - I have another challenge waiting in the wings.
trm2
 
Posts: 156
Joined: Wed Jan 15, 2020 12:47 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby bru » Fri Feb 14, 2020 7:12 pm

Tweezy...

(.*- )(([A-Z]).*?([A-Z]).*?([A-Z]).*?([A-Z]).*?([A-Z]).*?([A-Z])[^A-Z]*)$
\1\2-\3\4\5\6\7\8

SunFly116_12-The Beatles- I Want To Hold Your Hand.mkv ---> SunFly116_12-The Beatles- I Want To Hold Your Hand-IWTHYH.mkv
bru
 
Posts: 62
Joined: Wed Jan 31, 2018 7:35 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby bru » Fri Feb 14, 2020 7:42 pm

This one's better.. Wont touch previously renamed files.. Protect against names like:
SunFly116_12-The Beatles- I Want To Hold Your Hand-IWTHYH-IWTHYH.mkv

(.*- )(([A-Z]).*?([A-Z]).*?([A-Z]).*?([A-Z]).*?([A-Z]).*?([A-Z])[^A-Z]+)$
\1\2-\3\4\5\6\7\8
bru
 
Posts: 62
Joined: Wed Jan 31, 2018 7:35 pm

Re: Just for Fun – an Impossible Task – Append Initials of Song

Postby trm2 » Thu Feb 20, 2020 10:54 pm

I am humbled by the Experts - Thank you for playing!
trm2
 
Posts: 156
Joined: Wed Jan 15, 2020 12:47 pm


Return to Javascript Renaming


cron