Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Facets and alphabetical grouping (Read 2960 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Facets and alphabetical grouping

I'm trying to setup fb2k to behave like many players do "out of the box", with the ability to group tracks alphabetically. It's for someone who's extremely computer illiterate. I'm using Facets columns, but I'm wondering if anyone can suggest a less convoluted or better syntax for doing this. It works, but I'm still curious. Thinking about it, I'm not even sure I understand why the final line achieves the desired result, but it does.

The syntax I'm using for the alphabetical column is below. The attached screenshot shows the result. The second column displays %title%. I've split the syntax into multiple lines so it's easy to follow.

Thanks.

$puts(TITLE,$replace(%title%,'',,'(',))
$puts(NUM,
$ifequal($strchr($left($get(TITLE),1),0),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),1),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),2),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),3),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),4),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),5),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),6),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),7),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),8),1,0-9,)
$ifequal($strchr($left($get(TITLE),1),9),1,0-9,))
$ifequal($len($get(NUM)),3,$get(NUM),$left($get(TITLE),1))


PS. For some reason if I use 0 - 9 above rather than 0-9 it won't work. That might be a Facets quirk, but if anybody knows why....
PPS. Is there a way to compare strings directly rather than by their length as I have for the last line above?
Something like $if(%directoryname%,"My Music Folder",then, else)

Cheers.

Re: Facets and alphabetical grouping

Reply #1
I wanted something similar, but used the “$replace()” function instead:
Code: [Select]
$replace($left($caps($stripprefix([%album artist%])),1),0,#,1,#,2,#,3,#,4,#,5,#,6,#,7,#,8,#,9,#)
What this does is remove certain prefixes (e.g. “The”), truncates the artist’s name to the first letter, and then replaces any numbers with the “#” symbol.

If you’d prefer to stick with “0-9”, then you can use the following instead:
Code: [Select]
$replace($left($caps($stripprefix([%album artist%])),1),0,0-9,1,0-9,2,0-9,3,0-9,4,0-9,5,0-9,6,0-9,7,0-9,8,0-9,9,0-9)
If you have any artists that begin with accented letters, you can just add them to the replace function to have them filtered to the non-accented letter:
Code: [Select]
$replace($left($caps($stripprefix([%album artist%])),1),0,#,1,#,2,#,3,#,4,#,5,#,6,#,7,#,8,#,9,#,Ó,O,Ü,U)

Re: Facets and alphabetical grouping

Reply #2
beardgoggles,

Thank you. That's much simpler (I'm grouping by title, but it's the same idea).

I eventually worked out I still had to clear the junk from the beginning of the title first, as I had before (titles that begin with an opening bracket or single quote, and removing spaces etc) and I hadn't thought about using $caps or $stripprefix. What I've ended up with does the same job, only better, and it's far less convoluted.

Thanks again!

Edit: For some reason $stripprefix doesn't want to work unless it's being used directly with the %title% field, so I've had to move it up to the $puts line. Maybe I'm missing something...

Code: [Select]
$puts(TITLE,$replace($stripprefix(%title%),!,,#,,'',, ,,'(',))
$replace($left($caps($get(TITLE)),1),0,0 - 9,1,0 - 9,2,0 - 9,3,0 - 9,4,0 - 9,5,0 - 9,6,0 - 9,7,0 - 9,8,0 - 9,9,0 - 9)

Re: Facets and alphabetical grouping

Reply #3
(I'm grouping by title, but it's the same idea).
Sorry – I noticed that you were after title rather than artist after posting! 😖

Edit: For some reason $stripprefix doesn't want to work unless it's being used directly with the %title% field, so I've had to move it up to the $puts line. Maybe I'm missing something...
It could have been a missing bracket or comma, as I was able to wrap a $replace function inside $stripprefix successfully.

Also, if you want to have the code in a single line without needing a $puts function, try the following and see if it works for you:
Code: [Select]
$replace($left($caps($stripprefix($replace(%title%,-,,!,,¡,,¿,,#,,'',,",,“,,‘,,’,, ,,'(',,'[',,'$',,*,,.,))),1),0,0 - 9,1,0 - 9,2,0 - 9,3,0 - 9,4,0 - 9,5,0 - 9,6,0 - 9,7,0 - 9,8,0 - 9,9,0 - 9)
(The above example also adds in some characters that I have in track titles in my foobar2000 library.)

Re: Facets and alphabetical grouping

Reply #4
beardgoggles,

Thanks again!

I tried the syntax from your last post but for some reason $stripprefix won't work that way for me. At least not how I expect it to. Here's what happens using your above method. You can see from the first screenshot, everything beginning with "The" is to be found under "T" using your recent syntax. When I use the $puts line and move $stripprefix to there, it works like the second screenshot. I've tried it with and without the Facets option to ignore the leading "The" when sorting, but it made no difference. I've been meaning to rename everything beginning with "The" anyway. Now I might find the motivation (renaming "The Strangest Thing" to "Strangest Thing, The" etc). I've done that for many tracks, but there's plenty to do. Gremlins....
Later on I might try again on a fresh fb2k install without most of the additional plugins to see if anything changes. It's also odd that using "0 - 9" as a folder wouldn't work for my previous method (nothing would display) so I had to use "0-9" instead. Using your method, either of them work.

Cheers.

Edit: I'm adding the following info for anyone else who might stumble across this thread.
One particular setup I'm configuring fb2k for has folders for some albums, and a large main folder with mixed artists and titles. I've finally worked out how to use alphabetical sorting only for the "Mixed" folder. It relates to my question in the opening post regarding comparing strings. Either I wasn't using $strcmp correctly, or there were more gremlins when I tried it originally, but the following only creates an alphabetical column for a folder called "Mixed". The rest of the folders are simply grouped by folder name. To make it work sensibly I've used two columns for the first Facets pane, with the first column simply displaying "Folder" (a Facets default column). The end result is the third screenshot.

I've split the lines again so it's easier to follow.

Code: [Select]
$if($strcmp(%directoryname%,Mixed),
$puts(TITLE,$replace($stripprefix(%title%),!,,#,,'',, ,,'(',))
$replace($left($caps($get(TITLE)),1),0,0 - 9,1,0 - 9,2,0 - 9,3,0 - 9,4,0 - 9,5,0 - 9,6,0 - 9,7,0 - 9,8,0 - 9,9,0 - 9),
%directoryname%)

 

Re: Facets and alphabetical grouping

Reply #5
Hi there,

My (unsolicited) thoughts - I would not be renaming any of TITLE fields, that is the job of title formatting and why the likes of $stripprefix / $swapprefix exist in the first place. Just get the code right and save yourself the unnecessary re-tagging work.

It's also odd that using "0 - 9" as a folder wouldn't work for my previous method (nothing would display) so I had to use "0-9" instead.
(Although you are not using this method anymore...)

Probably because $ifequal and $len is asking how many characters -

Quote
$ifequal($len($get(NUM)),3, ...

"0-9" = 3 characters, "0 - 9" = 5 characters.

Cheers

Re: Facets and alphabetical grouping

Reply #6
My (unsolicited) thoughts - I would not be renaming any of TITLE fields, that is the job of title formatting and why the likes of $stripprefix / $swapprefix exist in the first place. Just get the code right and save yourself the unnecessary re-tagging work.

I think I started doing it because my portable MP3 player doesn't do any title formatting.

Probably because $ifequal and $len is asking how many characters -

I checked and it seems you're correct. I thought I'd tested it properly, but maybe that's what I did silly.

Thanks.

Re: Facets and alphabetical grouping

Reply #7
You can also use pipes for heirarchical formatting, e.g.

<<<$caps($cut($stripprefix(%title%),1))>>>|$stripprefix(%title%)

Re: Facets and alphabetical grouping

Reply #8
mjm716,
Thanks for that, but unfortunately I couldn't get it to work as I needed it to in this context.

For anyone who's interested though, I worked out how to reduce alphabetical sorting for a single folder to a single Facets pane, rather than using dual columns in order to keep the folders sorted properly as I had for the example in my previous post.

Code: [Select]
$if($strcmp(%directoryname%,Mixed),
$puts(TITLE,$replace($stripprefix(%title%),!,,#,,'',, ,,'(',))
Mixed    $replace($left($caps($get(TITLE)),1),0,0 - 9,1,0 - 9,2,0 - 9,3,0 - 9,4,0 - 9,5,0 - 9,6,0 - 9,7,0 - 9,8,0 - 9,9,0 - 9),
%directoryname%)

Re: Facets and alphabetical grouping

Reply #9
You can also use pipes for heirarchical formatting, e.g.

<<<$caps($cut($stripprefix(%title%),1))>>>|$stripprefix(%title%)

To revive this thread again....
Does anyone know where pipes can and cannot be used for hierarchical formatting?
I've tried experimenting with it for a playlist column, but without any success.

For the following example, a custom playlist title column displays something like:

Ashestoashes|Ashes To Ashes

indicating that "|" is interpreted as literal text.

$caps($replace($stripprefix(%title%),!,,#,,'',,.,, ,,'(',))|$swapprefix(%title%)

Thanks.

Re: Facets and alphabetical grouping

Reply #10
Does anyone know where pipes can and cannot be used for hierarchical formatting?

As far as I know, only in the album list. In facets they are used to merge two or more fields in one column and elsewhere it should be a literal.




P.S.

BTW another way to select numbers is to convert the single character to a one digit number and than compare the two values:
Code: [Select]
$puts(i,$left(%title%,1))$if($strcmp($num($get(i),1),$get(i)),0-9,$get(i))
I'm late

Re: Facets and alphabetical grouping

Reply #11
BTW another way to select numbers is to convert the single character to a one digit number and than compare the two values:
Code: [Select]
$puts(i,$left(%title%,1))$if($strcmp($num($get(i),1),$get(i)),0-9,$get(i))


Similarly you can select special characters by comparing the uppercase and the lowercase version:
Code: [Select]
$puts(i,$left(%title%,1))$if($strcmp($num($get(i),1),$get(i)),0-9,$if($strcmp($lower($get(i)),$upper($get(i))),#,$get(i)))
I'm late

Re: Facets and alphabetical grouping

Reply #12
Thanks for the info.

For the record, they can be found in the default sorting patterns under Advanced/Display. ie
File Path=%path_sort%;Artist=%artist%|%date%;
At least I assume that's what they are.

It'd be lots of fun if pipes could be used everywhere though. Oh well....

Re: Facets and alphabetical grouping

Reply #13
For the record, they can be found in the default sorting patterns under Advanced/Display. ie
File Path=%path_sort%;Artist=%artist%|%date%;

That's actually a literal. Since they don't affect the sort order, literals are used to make the sort pattern more readable, but it doesn't necessarily have to be a pipe, You can easily remove it or replace it with any character you like, as long as it does not have a special meaning in titleformatting.
I'm late

Re: Facets and alphabetical grouping

Reply #14
Concerning the OP, I forgot one last bit: you can use the $ascii() function to group diacritic characters (such as "à" or "ä") as simple letters (such as "a"). This below is the complete pattern I use in EsPlaylist to group artists by their initial:

Code: [Select]
$puts(i,$upper($ascii($left($replace($stripprefix(%<artist>%),'',,",),1))))$if($strcmp($num($get(i),1),$get(i)),#,$if($strcmp($lower($get(i)),$get(i)),&,$get(i)))


I'm a CUI user, therefore I'm not too familiar with facets. Unlike facets or DUI album list, EsPlaylist does not remap tags by default, so I think you would need to use the $meta_branch() function instead of the %<field>% syntax for splitting values, but you get the idea. If you are working on a non-mutivalue field, such as the track title, just replace %<artist>% with %title% and it should work fine.
I'm late

Re: Facets and alphabetical grouping

Reply #15
Thanks davideleo.
I'm not sure I have a use for it myself at the moment, but I've added your syntax as a column for a rainy day.
For the record, it sorts exactly the way you described using Facets panes. The first "Artist Sort" column uses your syntax.


Re: Facets and alphabetical grouping

Reply #16
PS I can't find a reference to the $meta_branch() function so I'm not sure I understand that one.

Re: Facets and alphabetical grouping

Reply #17
PS I can't find a reference to the $meta_branch() function so I'm not sure I understand that one.

Here it is. I'm not sure I understand it either, though. :D
I only remember from past experiments that facets behaved weirdly with my code, but it behaved weirdly only in case of multiple values. That was a few foobar2000 versions ago and it might be an outdated issue by now. Since I don't use facets in my skin, I never really looked into it.


P.S.
I just noticed after posting the link above, here's what the note to multivalue field syntax says: "Note that some title formatting functions are incompatible with fields that have been split this way. This applies to string comparison and measuring functions...". In other words, in facets, the $strcmp() function does not work on split values.
I'm late

Re: Facets and alphabetical grouping

Reply #18
Ahhhh..... I didn't realise you were referring to a Facets specific function and not a standard title formatting one.

Thanks.