INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Generating Tags from Path - Regex to the rescue  (Read 1080 times)

jacobacci

  • Galactic Citizen
  • ****
  • Posts: 256
Generating Tags from Path - Regex to the rescue
« on: May 01, 2018, 10:50:58 am »

I have a question to the regex wizards in this forum.

I would like to help a friend generate tags for his (huge) library. So far he has always browsed via folder names.

For 80% of the library, the folder structure is very standard. Easy to generate tags from these folder names using F12:
W:\
  \ROCK A-F\
    \Artist\
      \Album\
       \filename.ext


For about 20% of the library (the 120'000 tracks in question) the structure is slightly different and contains an extra folder level:
W:\
  \ROCK A-F\
    \Artist\
      \z_Outtakes & Live\
        \Album\
          \Sometimes there is a folder here indicating Disc 1,2,3\
            \filename.ext\
He uses this structure to navigate directly to the outtakes.

The folder "z_Outtakes & Live" is always spelled exactly like this and it is always located at the same level. Artist sits above it and Album below it.

I assume the following could be done using Regex:
  • use filename(path) as input
  • find \z_Outtakes & Live\
  • capture to the left until the next backslash

Similarly capture to the right until the next backslash for Album

I would put the Regex into an expression column to check whether the output is correct.
Finally I'd put the Regex into the Artist and Album fields to fill them.

I have tried to build a Regex expression, but could only get it to identify characters at the beginning of the path (W:\....), not a substring in the middle of the pathname.

Could one of the resident regexperts point me in the right direction?
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Generating Tags from Path - Regex to the rescue
« Reply #1 on: May 01, 2018, 11:25:35 am »

No need to resort to Regex from what you described. This can all be done in a 2-3 batches with the regular Fill Properties from Filename tool.

Steps:

0. Import all files into MC.

1. Select all files, and apply Fill Properties from Filename using a template appropriate for this filename structure: W:\ROCK A-F\Artist\Album\filename.ext

Note that this will apply the wrong tags for files that are in the other, different, folder structure. But you can ignore these, as you'll fix them in the next step(s). That'll get you 80% of the way there.

2. Now, let's get all of those z_Outtakes folders. Make a Smartlist with the rule:
Code: [Select]
[Filename]="\z_Outtakes & Live"
This will give you a list of just those files where your previous Fill Properties from Filename template didn't work right. This will let you use the Fill Properties tool again on just these to overwrite the (wrong) data you filled in the previous step, which is why you could ignore these the first time around.

3. Control-A to select all of these files, and apply a new Fill Properties from Filename template which matches this folder structure. This time, you can ignore the [Disc #] folder "tier" (assuming they don't all have that Disc part of the structure, as you indicated), because you can do those in the next step.

4. Now to deal with the [Disc #] tier of the folder structure. You didn't specify, but the easiest will be if the folders always have something prefixing the disc number. For example, if they are something like:
\Album\Disc 1\filename.ext or \Album\d1\filename.ext.
In this case, modify your Smartlist above (or make a new one if you want) with the following rule:
Code: [Select]
[Filename]="\z_Outtakes & Live" [Filename]="\Disc"Alter that second rule to make it match only the ones that actually contain the [Disc #] tier.

If not, it is a bit more challenging, but not the end of the world. This kind of thing would work:
Code: [Select]
[Filename]="\z_Outtakes & Live" ([Filename]="\1\" or [Filename]="\2\" or [Filename]="\3\" or [Filename]="\4\")That would capture any folder which is named only 1, 2, 3, or 4. If you need to go much higher, there's certainly a more clever way to do it, but assuming she doesn't have 16-disc sets, you should be fine with this method.

5. Now you have a list of only the files in the \z_Outtakes & Live\ subdirectories, and of those, only the ones that contain [Disc #] data in the filenames. Control-A on these and do your last Fill Properties from Filename rule to import that data.

Done. Delete the smartlists you used to make them, and construct some nice Views so she can browse her files like she was used to, and also in new and creative ways.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Generating Tags from Path - Regex to the rescue
« Reply #2 on: May 01, 2018, 11:41:43 am »

Also worth mentioning... Your friend obviously prefixed the z_ on the Outtakes folder in order to make these "special" albums always "sort" to the bottom of the Album listing for each Artist.

You can do the same thing in MC, but you don't have to make it so ugly as that! The way I'd do it is:

1. Make a new Library Field in MC called [Outtakes or Live Album] (or something like that) with the following settings:

click to embiggen


2. Tag all of the files in that z_Outtakes Smartlist with a checkmark in this new field (make it equal to 1).

3. Show this field in a column in your Media Views, to make it easy to see and tag new files with it if needed in the future. The nice thing about making it a Relational Field keyed on [Album] (as I did in my screenshot above) is that you only have to check the checkbox for one file for any song on an album, and they'll all automatically get the checkmark.

Newly imported albums will automatically import with this field set to 0, but it'll take literally checking a single checkbox on any file in the album to switch the entire album over after import.

4. Define a sort order that includes this field, so that the albums which have this checkmark checked automatically sort down below the "unchecked" albums. Since the actual internal values of the checkmark field are 0 and 1 (and 0 sorts before 1) this will be simple:
Code: [Select]
~sort=[Artist],[Outtakes or Live Album],[Album],[Disc #],[Track #],[Name]
Then your [Album] tag can really contain only the clean name of the Album, but he or she will still get the sort order they like.

5. For bonus points, make a Tag on Import rule so that any new album imported which contains a "z_Outtakes" folder automatically gets this checkmark applied.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

jacobacci

  • Galactic Citizen
  • ****
  • Posts: 256
Re: Generating Tags from Path - Regex to the rescue
« Reply #3 on: May 01, 2018, 11:52:00 am »

This is brilliant, Glynor. Thanks

I continue to be amazed at what can be done with MC.
Building on what you suggested, I think I will attack the problem as follows:

Select the files with [Filename]="\z_Outtakes & Live"
Then extract four levels of tags from the folder structure (just to be sure, I don't know if there are some further directories below the disc one). As the files have no tags yet, I can use Composer, Conductor etc.
Then check which Tag contains "z_Outtakes & Live". That will give me 2-3 groups of files to work on and apply the fitting tag generation rule to them.

I had already thought to add a tag for the outtakes and then get rid of the directory level to bring the whole structure to something standard.
But then "Tag on import" - WOW!

Being from Switzerland, I like your signature about the cheese!


Logged

~OHM~

  • Citizen of the Universe
  • *****
  • Posts: 1825
  • "I Don't Play The Music The Music Plays Me"
Re: Generating Tags from Path - Regex to the rescue
« Reply #4 on: May 01, 2018, 02:59:11 pm »

This is brilliant, Glynor. Thanks

Being from Switzerland, I like your signature about the cheese!
LOL....I'm wondering what happend to the GIANT steak....lol

Logged
“I've Reached A Turning Point In My Life. I Now Realize I Have More Yesterdays Then Tomorrows”

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Generating Tags from Path - Regex to the rescue
« Reply #5 on: May 01, 2018, 07:40:29 pm »

Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72446
  • Where did I put my teeth?
Re: Generating Tags from Path - Regex to the rescue
« Reply #6 on: May 01, 2018, 07:50:18 pm »

How about a Honey Baked Ham for you and one for Awesome Donkey, in honor of your generous work on skins?

Or a package of Hebrew National Beef Franks?
Logged

jacobacci

  • Galactic Citizen
  • ****
  • Posts: 256
Re: Generating Tags from Path - Regex to the rescue
« Reply #7 on: June 03, 2018, 09:40:23 am »

Thanks for your suggestions, Glynor. Your method worked perfectly.
It proved very flexible in identifying 5 different types of path threes, the most complex one containing

Artist
z_Outtakes
Album
AlbumSubFolder1
AlbumSubFolder2
Disc#
Track.flac

I was able to extract this into the respective Tags and then concatenate the 3 Album Tags into one.
Obviously I screwed up a few times along the way, but as all the info was still there in the path structures, I could simply redo the parsing.

Thanks a lot for your help.
Logged
Pages: [1]   Go Up