Skip to main content

Topic: Multi-value field w/ duplicated value, any way to show it only 1 time? (Read 1207 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • silkcut
  • [*][*]
Multi-value field w/ duplicated value, any way to show it only 1 time?
Hello.  Does anyone know how to compare values in multivalue fields and if they are the same then just display the value once?

e.g. say my PUBLISHER tag has Sire;Sire;Sire  (It's stupid I know but I use Discogs Tagger and Discogs has multiple values for record labels even if it is the same record label.) , how can I have foobar2000 test for this and only display Sire?

Right now in my SimPlaylist grouping I have:

Code: [Select]
[$crlf()$replace(>>$meta_sep(PUBLISHER,' / ') ,', ',$crlf()>>)]


which inserts a "/" in between the values if they are different. e.g. "Sire / Mute" if PUBLISHER field is "Sire; Mute".  But it still shows "Sire / Sire / Sire" when I would like it to just show "Sire".

Thanks!!

  • BenB
  • [*][*][*][*][*]
Multi-value field w/ duplicated value, any way to show it only 1 time?
Reply #1
Try this:
Code: [Select]
$if($and($greater($meta_num(publisher),1),$strcmp($meta(publisher,1),$meta(publisher,2))),
$meta(publisher,1),
$meta_sep(publisher,' / '))

It checks to see if there are multiple values and the first and second values match. If they do, it returns only the first value. Otherwise it returns all values (including a tag with a single value).

I'll let you figure out how to incorporate it into your existing title formatting. I'd fix the duplicate tags if I were you.
  • Last Edit: 02 February, 2013, 06:36:45 PM by BenB

  • BenB
  • [*][*][*][*][*]
Multi-value field w/ duplicated value, any way to show it only 1 time?
Reply #2
Scratch that title formatting. It should be:
Code: [Select]
$if($and($greater($meta_num(publisher),1),$strcmp($meta(publisher,0),$meta(publisher,1))),
$meta(publisher,0),
$meta_sep(publisher,' / '))

Ugh. I can't believe I forgot the enumeration begins with 0.

  • silkcut
  • [*][*]
Multi-value field w/ duplicated value, any way to show it only 1 time?
Reply #3
Thanks.  This will help.

Yes I think I will fix the tags instead.  Is there a command that will remove duplicate values?  i.e. %PUBLISHER% "Sire;Sire;Sire" ----> "Sire"

  • BenB
  • [*][*][*][*][*]
Multi-value field w/ duplicated value, any way to show it only 1 time?
Reply #4
No, there is nothing I'm aware of that will remove duplicates for you.

The script I gave you is based on the assumption that if the 1st and 2nd values match (a=b), then the 1st and 3rd values also match (a=c), thus all three values match (a=b=c). If this is always true then the script can be modified to this:
Code: [Select]
$if($and($greater($meta_num(publisher),1),$strcmp($meta(publisher,0),$meta(publisher,1))),$meta(publisher,0),$meta(publisher,0)[; $meta(publisher,1)[; $meta(publisher,2)]])

for use with "Format from other fields" in the Properties dialog. It also assumes that the tag will never have more than 3 values.

On the other hand, if there are other scenarios, such as:
Code: [Select]
a=b,a≠c
a≠b,a=c
a≠b,a≠c,b=c

then the script will have to be modified to take them into account to remove duplicates.
  • Last Edit: 08 February, 2013, 12:04:51 PM by BenB

  • silkcut
  • [*][*]
Multi-value field w/ duplicated value, any way to show it only 1 time?
Reply #5
Great.  Thanks so much for your help!

  • BenB
  • [*][*][*][*][*]
Multi-value field w/ duplicated value, any way to show it only 1 time?
Reply #6
You're welcome. I'm glad it worked for you.

I went ahead and wrote a script for use with "Format from other fields" that takes the scenarios into account I mentioned in my last post. Another difference is that it takes tags having more than 3 values into account and leaves them unchanged. I wasn't going to post it unless you couldn't use that last script I gave, but I'll post it anyway. I could probably tidy it up a bit using variable operations but meh.

Code: [Select]
$ifequal($meta_num(publisher),3,$if($and($not($strcmp($meta(publisher,0),$meta(publisher,1))),$not($strcmp($meta(publisher,0),$meta(publisher,2))),$not($strcmp($meta(publisher,1),$meta(publisher,2)))),$meta_sep(publisher,'; '),$if($not($strcmp($meta(publisher,0),$meta(publisher,1))),$meta(publisher,0); $meta(publisher,1),$if($not($strcmp($meta(publisher,0),$meta(publisher,2))),$meta(publisher,0); $meta(publisher,2),$meta(publisher,0)))),$ifequal($meta_num(publisher),2,$if($not($strcmp($meta(publisher,0),$meta(publisher,1))),$meta(publisher,0); $meta(publisher,1),$meta(publisher,0)),[$meta_sep(publisher,'; ')]))
  • Last Edit: 10 February, 2013, 06:08:55 PM by BenB