Page 1 of 1

Add artist name to file ONLY if the artist name isnt present

PostPosted: Thu Aug 24, 2023 4:29 pm
by KINGLIFER
I have a ton of videos I just moved.
Now I have a new delema.
I have files like this.
Code: Select all
X:\MUSIC VIDEOS\Alanis Morissette\Alanis Morissette - You Oughta Know.mkv

I unfortunately have files like this as well...

Code: Select all
X:\MUSIC VIDEOS\Alanis Morissette\You Oughta Know.mkv


All folders are the same. Some are mkv or Mp4 (if that matters)

What I want is to search all folders under X:\MUSIC VIDEOS\ and check if the 2 nested folder (X:\MUSIC VIDEOS\Alanis Morissette\) has files. If it does does the folder above it name is in the file's name. If it is skip. If it isnt add it.
In this example the added name would be
Code: Select all
Alanis Morissette -

There is a space after the minus.

I did do a search and found a lot of examples and I tried a few but they do not work from a level of all artists folders I have.

Thank you as well for taking time to read.

Re: Add artist name to file ONLY if the artist name isnt present

PostPosted: Thu Aug 24, 2023 4:32 pm
by KINGLIFER
I could not edit a grammar issue...

If it does, is the name of the folder above it included in the file's name? If it is, skip it. If it isn't, add it.

Prefix "ParentFolder - " unless already prefixed

PostPosted: Fri Aug 25, 2023 8:29 am
by Luuk
Its unfortunate, but only Javascript(14) and AppendFolderName(9) can look at the file's folder-path.
So with having the paid version, can use javascript, but it depends on which sub-folders to conduct??

To conduct any sub-folder, can use some javascript like...
prefix = object('folder').replace(/.*\\([^\\]*)\\$/, '$1 - ')
if (!name.startsWith(prefix)) {newName = prefix + name}

To conduct sub-folders at 1-level below "X:\MUSIC VIDEOS\", its more like...
prefix = object('folder').replace(/.*\\([^\\]*)\\$/, '$1 - ')
if (/X:\\MUSIC VIDEOS\\[^\\]*\\$/.test(object('folder'))) {if (!name.startsWith(prefix)) {newName = prefix + name}}


But without having the paid version to javascript rename, would need to conduct 2-separate renames.
First would use AppendFolderName(9) to prefix all of your filenames, even if they're already prefixed.
Then could use RegEx(1) with a checkmark for "v2", so then a "Match" and "Replace" like...
^(.+? - )\1+
$1

This way, if AppendFolderName(9) invented too many prefixs, then RegEx(1) could fix them like...
Artist1 - Artist1 - Artist1 - Artist1 - Song.mp4 ===> Artist1 - Song.mp4

Re: Add artist name to file ONLY if the artist name isnt present

PostPosted: Fri Aug 25, 2023 10:18 am
by KINGLIFER
Thank you. I do not have the paid.

So to be clear because I am not sure what exactly must be done...
I use AppendFolderName(9)
then RegEx(1) with this: ^(.+? - )\1+
$1

right?



Thank you again!

Re: Add artist name to file ONLY if the artist name isnt present

PostPosted: Fri Aug 25, 2023 11:28 am
by KINGLIFER
Ok so I tried it and thank you, it worked but about 300 or so wont do the second part.

for example.
Code: Select all
A$AP Rocky - A$ap Rocky - Wild For The Night (Feat. Skrillex & Birdy Nam Nam) (Clean - Official Video).mkv


wont change to
Code: Select all
A$AP Rocky - Wild For The Night (Feat. Skrillex & Birdy Nam Nam) (Clean - Official Video).mkv


if I use
Code: Select all
^(.+? - )\1+
$1

Re: Add artist name to file ONLY if the artist name isnt present

PostPosted: Fri Aug 25, 2023 12:22 pm
by KINGLIFER
Using what you gave me and some help from chatGTP if anyone else ever has this problem

Code: Select all
^(.+? - )(?i)\1+


This is the response from ChatGTP to help people understand why:

Given that Bulk Rename Utility has a v2 section, it indicates that you're using a more advanced version of regular expressions that can handle backreferences. Here's how you can achieve your goal using that:

For filenames with variations in capitalization, you can use the following expression in the "v2" section:

**Match:**
Code: Select all
^(.+? - )(?i)\1+


THANK YOU SOOO MUCH @Luuk

**Replace:**
Code: Select all
$1


Explanation:

- `^`: Start of the line.
- `(.+? - )`: Capture group that matches a sequence of characters followed by " - ".
- `(?i)`: This is an inline flag to make the rest of the pattern case-insensitive.
- `\1+`: Match the same sequence captured in the first group one or more times.

By using `(?i)`, you're making the pattern case-insensitive, which means it will match variations in capitalization.

This should work for the examples you provided:

- `2Pac - 2pac - Baby Don't Cry (Keep Ya Head Up II).mkv`
- `$NOT - $not - Doja.mkv`

It will replace the filenames with the correct case while removing the repetitions of the repeated sequence.

Make sure to test this in the "v2" section of Bulk Rename Utility to ensure it works as intended.

Prefix "ParentFolder - " unless already prefixed

PostPosted: Fri Aug 25, 2023 11:19 pm
by Luuk
Yes, nothing was included to be case-insensitive, but really AppendFolderName(9) should never do that?
Unless maybe somebody added a prefix, then changed the folder-case, and then conducts more prefixs?
But as long as only the case was changed, then (?i) can still match any of your extra prefixs.

Javascript users have many ways to case-insensitive match.. To prefix any sub-folder not starting like "ParentFolder - " ....
prefix = object('folder').replace(/.*\\([^\\]*)\\$/, '$1 - ')
start = new RegExp('^'+prefix,'i')
if (!name.match(start)) {newName = prefix + name}

To only prefix within sub-folders exactly 1-level below any folder named "Music Videos"...
prefix = object('folder').replace(/.*\\([^\\]*)\\$/, '$1 - ')
start = new RegExp('^'+prefix,'i')
if (/.*\\Music Videos\\[^\\]*\\$/i.test(object('folder'))) {if (!name.match(start)) {newName = prefix + name}}

Can remove either red "i" if wanting "Music Videos" or the filenames to be case-sensitive.
Glad you found a solution with (?i).. I wish that it works without having the "v2" checkmark!