INTERACT FORUM

Please login or register.

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

Author Topic: Custom library field named by folder as positioned from root  (Read 782 times)

Library Eye

  • Junior Woodchuck
  • **
  • Posts: 63
Custom library field named by folder as positioned from root
« on: March 18, 2023, 05:58:33 pm »

I have an incredibly simple goal and've tried a variety of expressions seen throughout the forum and though I've had luck with other such endeavors, having no luck this time so asking.

I simply want to create a custom Library Field, let's call it
Album Artist (by directory)
which is always generated from the name of corresponding folder at a certain position from start / root of library file path, not from file on backwards toward root as the number of subfolders can vary that way whereas position of targeted folder is constant from the start of root.

Hence, if my library is gathered by album artist on a disk named
MC_Disc
in a folder name
MC_Music
the targeted directory to populate this field would be at fourth position below, as represented by an *, with path shown in manner MediaCenter displays same path to Library in macOS.

Volumes/MC_Disc/MC_Music/*/AlbumName/SongTitle.ext

For example, all of the following—

Volumes/MC_Disc/MC_Music/Miles Davis/Milestones/Two Bass Hit.flac
Volumes/MC_Disc/MC_Music/Miles Davis/Sorcerer/Limbo.flac
Volumes/MC_Disc/MC_Music/Miles Davis/Live/Agharta/CD1/Prelude.m4a
Volumes/MC_Disc/MC_Music/Miles Davis/Circle in the Round/CD2/Side Car I.ogg

would populate the custom
Album Artist (by directory)
field with
Miles Davis


This seems very obvious so not sure how everything I've tried yet is failing in one way or another. In addition to simpler attempts, using this Windows solution and changing the back slashes to forward for macOS didn't work; turns out I had to leave in the Windows backwards slashes for some reason.
https://yabb.jriver.com/interact/index.php?topic=59233.0

So, working from that I can get
=ListItem([Filename (\Volumes\MC_Disc\MC_Music\)],Math(ListCount([Filename (\Volumes\MC_Disc\MC_Music\)],\)-2),\)

to fill the custom field with "MC_Music" but that's not what I need; I need "Miles Davis" applied to field for files in
Volumes/MC_Disc/MC_Music/Miles Davis/

"Meredith Monk" for files in
Volumes/MC_Disc/MC_Music/Meredith Monk/

and so on.

Looks like I need to know the wildcard for final/fourth directory, and nothing I've tried works. And really it should be and probably is simpler than all that.

Thanks
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9094
Re: Custom library field named by folder as positioned from root
« Reply #1 on: March 19, 2023, 02:55:07 am »

Is it always the 4th item?
If yes, this should work. Does it?
Code: [Select]
=ListItem([Filename (Path)],3,//)

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2501
Re: Custom library field named by folder as positioned from root
« Reply #2 on: March 19, 2023, 03:07:55 am »

Or ListItem([Filename (Path)],5,//) as the 2 starting slashes also count.
Or ListItem(filepath(),5,//)

OP, you're confusing the field "[filename (path)]" with a function. It's not, you're not supposed to replace the (path) in there, it's literal.
Logged

Library Eye

  • Junior Woodchuck
  • **
  • Posts: 63
Re: Custom library field named by folder as positioned from root
« Reply #3 on: March 19, 2023, 05:54:38 pm »

Is it always the 4th item?
If yes, this should work. Does it?
Code: [Select]
=ListItem([Filename (Path)],3,//)
Yes! — well, specifically
=ListItem([Filename (Path)],4,//)
gets the job done!

Or ListItem([Filename (Path)],5,//) as the 2 starting slashes also count.
Or ListItem(filepath(),5,//)

OP, you're confusing the field "[filename (path)]" with a function. It's not, you're not supposed to replace the (path) in there, it's literal.
Yup — that is exactly the case, I understood ("path") to be placeholder for actual path, as in instruction to insert path there. I woulda eventually figured that out, I think!, but gosh coulda been a long long while…

Thank you both!

I now have that rule/expression third in another, "firstnotempty", expression, named "Album Artist (sort)," behind "[Album Artist Sort]" (which works for m4a and FLAC files which have that sorta tag already included) and "[ALBUMARTISTSORT"] (which works for ogg files which have that sorta tag already included) and ahead of "[Album Artist (auto)])" and now I have a nice tidy useful Artist view.
Logged
Pages: [1]   Go Up