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: Metadata - replace / remove / append values in multivalue fields ? (Read 987 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Metadata - replace / remove / append values in multivalue fields ?

Heya,
one workflow I have yet to find a good solution for that neither Musicbee nor Foobar can do (for foobar I use foo_masstagger for similar things, which works mostly, but things get tricky/impossible when it comes to multi value metadata with that as well...).

I often find myself wanting to append/remove/re-order multi-value metadata; mostly in Genre or Artist field...
For a practical example - I have (on multiple files, lets's say 2 mp3s w TCOn field, queried & prionted through mutagen python module):
Genre file 1:
TCON': TCON(encoding=<Encoding.LATIN1: 0>, text=[u'Metal', u'Drum n Bass', u'Dubstep'])
Genre file 2:
TCON': TCON(encoding=<Encoding.LATIN1: 0>, text=[u'Punk', u'Drum n Bass'])


There's 2 operations I'd love to do (ideally on multiple files, which might have different and/or differently ordered tags, which complicates things further...):

1)
append value at specific position.
eg:
In the above case, I would like to append 'Rock' at position 1.
So the result would be:
Genre file 1:
TCON': TCON(encoding=<Encoding.LATIN1: 0>, text=[u'Rock', u'Metal', u'Drum n Bass', u'Dubstep'])
Genre file 2:
TCON': TCON(encoding=<Encoding.LATIN1: 0>, text=[u'Rock', u'Punk', u'Drum n Bass'])

2)
Search for a value, and inject/remove another value:
eg:
In the above case, I would like to add 'Breakcore' behind 'Drum n Bass' (or replace replace u'Drum n Bass' value with values: u'Drum n Bass', u'Breakcore').
So the result would be:
Genre file 1:
TCON': TCON(encoding=<Encoding.LATIN1: 0>, text=[u'Rock', u'Metal', u'Drum n Bass', u'Breakcore', u'Dubstep'])
Genre file 2:
TCON': TCON(encoding=<Encoding.LATIN1: 0>, text=[u'Rock', u'Punk', u'Drum n Bass', u'Breakcore'])

Does anyone have suggestions for how to do this best in foobar ?
Or alternative software as I haven't tried mp3tag and some of the other mostly mp3 editors over the last years - does anyone know of one that has great search/replace/append functionality for the above issues w multi value metadata (on multiple files [on mp3 = fake multi value fields, and flac = true multi value fields] - which might have different tags/ordered tags even...?)

Cheers.
c.

Re: Metadata - replace / remove / append values in multivalue fields ?

Reply #1
Highlight and right click on your files in foobar and choose 'Properties/Automatically fill values'. Choose 'Other...' from the dropdown menu as source then input this next to it:
Code: [Select]
$replace(%genre%,', ','; ')
This simply reads the tags you already had and replaces all commas with semicolons. This is necessary so foobar interprets the string as multivalue and will rewrite the tags accordingly. To do your operations you'll slightly modify this base string to your liking.

1) Append something at the front (such as Rock):
Code: [Select]
Rock; $replace(%genre%,', ','; ')
Note that I added '; ' after Rock so foobar will once again interpret that value as multivalue.

If you wanted to insert a value at the end, then:
Code: [Select]
$replace(%genre%,', ','; '); Rock
Note that in this case you add the semicolon and space in front of Rock.

Inserting in the middle would be more involved but also doable. But I doubt you would use it all that often though.

2) Mess with a specific value:
Code: [Select]
$replace(%genre%,', ','; ','Drum & Bass','Drum & Bass; Breakcore')
Whereas you replaced all occurences of 'Drum & Bass' with 'Drum & bass; Breakcore'. Or in other words you inserted 'Breakcore' after every 'Drum and Bass'.

In all cases to finish, as 'Pattern' you can simply write:
Code: [Select]
%genre%
So the string above gets written to your GENRE tag as-is.

I'd suggest reading the wiki:
http://wiki.hydrogenaud.io/index.php?title=Foobar2000:Title_Formatting_Reference

Re: Metadata - replace / remove / append values in multivalue fields ?

Reply #2
Awesome!
Thanks a ton!
Odd/confusing though that 'Source' column of the 'Automatically Fill Values...' window displays the post $replace functions output, not the actual source... no ?

Also, in case anyone knows as I've had a look but could not find it - is this 'Automatically Fill Values...' window map-able to a hotkey ?

Cheers.
c.

Re: Metadata - replace / remove / append values in multivalue fields ?

Reply #3
Not really, because the entire purpose of the 'Automatically fill values' operation is to provide a string (which happens to be called source) which will be matched against another (called pattern) to decide how you want to cut up the source string into multiple parts and which parts will be omitted. You are basically asking why the source of the source is not listed. Because it is irrelevant at that point for the rest of the operation and because you yourself have set it up to begin with to be like that.

If you'd like to 'look up' sources on the fly, you could just write %genre% at first and see what the source column will look like then. Then you might realize you don't want the source string to have commas when dealing with multivalue fields, so you'll wrap it inside a $replace() function like the example I gave you. Then since you want to insert something in the front, you'll simply write that in front of it in plaintext. And so on.

It probably is a bit hard to wrap your mind around it at first (it was for me too at the beginning), so all you can do is try to keep using it until you figure it out for yourself.

Don't know if you can set up a shortcut for it.