Just in single click, batch find and replace, remove

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

Just in single click, batch find and replace, remove

Postby Jakov » Fri Mar 11, 2022 7:24 am

Hi,
Please is there any property to record a macro or something like this to do many commands or functions in BRU such as find and replace, remove ....etc in a single click
However, I have a list of files with this pattern
yt5s.com-Changing Video Size in Premiere Pro(360p)
I want to remove (yt5s.com-) and () with its content
I can do that by two steps through find and replace, in addition to Remove function (Crop ->Special (*))
According to this javascript code:
str = str.replaceAll("yt5s.com- ", "");
str = str.replaceAll((*), "");
the first line works fine, but the second not
Any help, please
Jakov
 
Posts: 46
Joined: Sat May 23, 2020 1:29 am

Re: Just in single click, batch find and replace, remove

Postby Luuk » Sat Mar 12, 2022 3:33 pm

Greetings Jakov. You can always save the different settings inside of a .bru-file with the menu "File, Save As".
Its unfortunate, but .replaceAll() wont grant using the wildcards, unless saying them inside of a /regex/g.
So the second one would need to look more like... str = str.replaceAll(/\(.*?\)/g, "")

But bru's javascript cant support regex inside of replaceAll(), so instead we just use .replace(/regex-match/g, 'replace')
If to only remove these texts from the very beginnings and ends, can probably just use some code like...

if (/^yt5s.com- *.+\(\d+p\)$/.test(name)) {newName = name.replace(/yt5s.com- *|\([^()]*?\)$/g, '')}
if (/^any-regex-file-match$/.test(name)) {newName = name.replace(/any-regex-1|any-regex2$/g, '')}

Im probably not to answer for about a week, because finally moving back to Germany, but if your names dont always end like (###p)?
You can change the file-match \d+p ==> [^()]*? and if to remove all (texts) even in the middle of filenames, can remove "$" after any-regex2.
Luuk
 
Posts: 494
Joined: Fri Feb 21, 2020 10:58 pm

Re: Just in single click, batch find and replace, remove

Postby Jakov » Sun Mar 20, 2022 7:22 am

Luuk wrote:Greetings Jakov.
Im probably not to answer for about a week, because finally moving back to Germany


Don't worry,
Thank you so much, my bro
You are awesome
Billion Thanks
Jakov
 
Posts: 46
Joined: Sat May 23, 2020 1:29 am

Re: Just in single click, batch find and replace, remove

Postby Jakov » Sat Jul 30, 2022 7:44 am

Luuk wrote:but if your names dont always end like (###p)?
You can change the file-match \d+p ==> [^()]*?


Deer Luuk,
Today, I faced some files ending with (128 kbps), I changed the \d+p to [^()]*? as you recommend, but doesn't works
Code: Select all
if (/^yt5s.com- *.+\(^()]*?)$/.test(name)) {newName = name.replace(/yt5s.com- *|\([^()]*?\)$/g, '')}
......

In my opinion, we want to edit the code to remove yt5s.com- at the beginning of the file name and any last () despite its content.
Furthermore, for yt5s.com-, sometime there is a space between .com and dash com - and sometimes not yt5s.com-
So how to fix these problems with my special thanks.
Jakov
 
Posts: 46
Joined: Sat May 23, 2020 1:29 am

Re: Just in single click, batch find and replace, remove

Postby Luuk » Sat Jul 30, 2022 10:08 am

Greetings Jakov.. It does look like just a bad copy/paste, probably because of the browser selection.
The first [ doesnt get copied, but then also the paste somehow destroys the \ right before )$/.
But to fix the space problem, I would probably edit it more like...

if (/^yt5s.com[- ]+.+\([^()]*?\)$/.test(name)) {newName = name.replace(/yt5s.com[- ]+|\([^()]*?\)$/g, '')}

yt5s.com -- Changing Video Size in Premiere Pro1(480p) =====> Changing Video Size in Premiere Pro1
yt5s.com-Changing Video Size in Premiere Pro2(360p) =======> Changing Video Size in Premiere Pro2
yt5s.com-Changing Video Size in Premiere Pro3(128 kbps) ===> Changing Video Size in Premiere Pro3
yt5s.com-Changing Video Size in Premiere Pro4(AnyText) ====> Changing Video Size in Premiere Pro4
yt5s.com Changing Video Size in Premiere Pro5(AnyText) ====> Changing Video Size in Premiere Pro5

If needing to be more exact, so that (AnyText) does not get removed, just post back because its very easy to change.
Luuk
 
Posts: 494
Joined: Fri Feb 21, 2020 10:58 pm

Re: Just in single click, batch find and replace, remove

Postby Jakov » Sat Jul 30, 2022 4:22 pm

Luuk wrote:Greetings Jakov..

Thanks so much for your reply
I did as you recommended, but without any results
the whole code that I used now is:
Code: Select all
if (/^yt5s.com[- ]+.+\([^()]*?\)$/.test(name)) {newName = name.replace(/yt5s.com[- ]+|\([^()]*?\)$/g, '')}
if (/^any-regex-file-match$/.test(name)) {newName = name.replace(/any-regex-1|any-regex2$/g, '')}

the file name as an example:
education music (128 kbps).mp3

Thanks again
Jakov
 
Posts: 46
Joined: Sat May 23, 2020 1:29 am

Re: Just in single click, batch find and replace, remove

Postby Jakov » Sat Jul 30, 2022 4:41 pm

Jakov wrote:I did as you recommended, but without any results


I'm so sorry deer Luuk, it works perfectly
my problem was raised because I didn't refresh my file list.

Thanks again and take your rest
Best Regards
Jakov
 
Posts: 46
Joined: Sat May 23, 2020 1:29 am

Re: Just in single click, batch find and replace, remove

Postby Luuk » Sat Jul 30, 2022 9:15 pm

Many apologies, I did first believe that all of your filenames should still be starting like... yt5s.com ??
But now Im guessing that some first-renames did already remove the yt5s.com, so must now remember....
The following if (conditions) will only test for how the names should end, so this some different ways that mightcan help...

To remove both conditions of yt5s.com at the beginning, and remove (AnyTextThatsNotParenthesis) from the ends of any filename...
if (/RegxFileMatch/.test(name)) {newName = name.replace(/--AnyRegex1--|---AnyRegex2---/g, '')}
if (/^.+\([^()]*?\)$/.test(name)) {newName = name.replace(/^yt5s.com[- ]+| *\([^()]*?\)$/g, '')}

To remove both conditions of yt5s.com at the beginning, and only remove (EndingText) that starts with a digit...
if (/Regex-File-Match/.test(name)) {newName = name.replace(/--AnyRegex1--|----AnyRegex2-----/g, '')}
if (/^.+\(\d+[^()]*?\)$/.test(name)) {newName = name.replace(/^yt5s.com[- ]+| *\(\d+[^()]*?\)$/g, '')}

To remove both conditions of yt5s.com at the beginning, and only remove ending-text like (360p) or (128 kbps) or (128 kps) or (1,280 bps)...
if (/Regex-File-Match/.test(name)) {newName = name.replace(/--AnyRegex1--|----- Any Regex2 -----/g, '')}
if (/^.+\(\d+[^()]*?\)$/.test(name)) {newName = name.replace(/^yt5s.com[- ]+| *\([\d,]+ *k?b?ps?\)$/g, '')}

But really, you dont need these if's anymore, since conducting files that dont need to begin with yt5s.com?
So instead of using... if (any-condition) {newName = whatever}, you can just use the newName = whatever parts.
Just be careful with the files being selected, or maybe to think of better conditions, to limit which files get renamed?

Im only used if (condition) {rename} in the first post, because it seemed like, not only must all of the files begin with yt5s.com,
But also, that the only files that should have their ending (text) removed, would be the filenames that also begin with yt5s.com.
So now, that very last code should really just look like...

newName = name.replace(/--AnyRegex1---|------AnyRegex2-------/g, '')
newName = name.replace(/^yt5s.com[- ]+| *\([\d,]+ *k?b?ps?\)$/g, '')

You could put a condition in front, like testing to see if its a video, but this does also make the conducting much slower...
if (/^video$/i.test(fileProperty('System.PerceivedType'))) {newName = name.replace(/^yt5s.com[- ]+| *\([\d,]+ *k?b?ps?\)$/g, '')}

If needing a condition in front, I would probably just test file-extensions, because its much faster than testing System.PerceivedType...
if (/wmv|mp4|mkv|mpe?g/i.test(ext)) {newName = name.replace(/^yt5s.com[- ]+| *\([\d,]+ *k?b?ps?\)$/g, '')}

I did see that before refreshing, there was a file without yt5s.com, but still having (128 kbps), so maybe some of these can help.
If its me, Im probably preferring the very last one, but please just to be careful with selecting which files to get renamed!
Luuk
 
Posts: 494
Joined: Fri Feb 21, 2020 10:58 pm


Return to Javascript Renaming