# Convert multivalue artist field to a featuring list with respect to album artist

**URL:** https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810
**Category:** Export
**Created:** [December 13, 2011, 1:23pm UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810 "2011-12-13T13:23:51Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [December 13, 2011, 1:23pm UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/1 "2011-12-13T13:23:51Z")

</div>

Dear all,

yesterday some guys bailed me out with nice tricks (in German: [/t/12805/1](https://community.mp3tag.de/t/12805/1) to count the ARTIST fields given in a file (I'm talking about FLAC with Vorbis Comments).

Now, I managed to convert while exporting multivalue ARTIST fields to a nice list of featured artists with respect to a given ALBUM ARTIST (you might call the field ALBUMARTIST without space).

As an example, we start with a FLAC file containing

```
ALBUM ARTIST=2Pac
ARTIST=2Pac
ARTIST=Dr. Dre
ARTIST=Roger Troutman

```

The following export script

```
$filename($getenv('temp')\test.txt,utf-8)

$iflonger($meta(artist,1),0,$puts(l,$len((feat. $replace($meta_sep(artist,$char(7)),%album artist%,,))))$puts(cl,$strrchr((feat. $replace($meta_sep(artist,$char(7)),%album artist%,,)),$char(7)))$puts(cf,$strchr((feat. $replace($meta_sep(artist,$char(7)),%album artist%,,)),$char(7)))$if($eql($get(cl),$get(cf)),(feat. $replace($meta_sep(artist,$char(7)),%album artist%,,$char(7),)),$replace($regexp($cutRight((feat. $replace($meta_sep(artist,$char(7)),%album artist%,,)),$add($sub($get(l),$get(cl)),1)),($char(7))(.*),$2) & $cutLeft((feat. $replace($meta_sep(artist,$char(7)),%album artist%,,)),$get(cl)),$char(7),$char(44) )),)

```

will produce

> [@](#):
>
> (feat. Dr. Dre & Roger Troutman)

.

For me, this is a great trick, however, there're more than 600 characters in a single line of the export script and if you want to avoid white space and line breaks in the output, the export script is hardly readable. (I don't know, how to include it nicely in the forum ...).

Feel free to use or improve it!

![:book:](https://community.mp3tag.de/uploads/default/original/1X/0036d5b68f6226c53f6c68abfd0a7b8096fd4505.gif ":book:")

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 14, 2011, 7:20am UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/2 "2011-12-14T07:20:00Z")

</div>

> [@LosMintos](#):
>
> Dear all, yesterday some guys bailed me out with nice tricks (in German: [/t/12805/1](https://community.mp3tag.de/t/12805/1) to count the ARTIST fields given in a file (I'm talking about FLAC with Vorbis Comments). ... The following export script ... is hardly readable ...

Although I am one of these guys you've mentioned, I cannot comprehend what you have coded.  
The scripting expression looks like as if there are too much round brackets and commas involved (slipping through the export scripting syntax checker).  
And what sense have ARTIST and ALBUM ARTIST in this script?  
Please advice.

DD.20111214.0920.CET

Hmm, maybe you can condense your script into this line ...

**%ALBUMARTIST%$iflonger($meta(ARTIST,1),0,' (feat. '$replace($meta\_sep(ARTIST,' & '),%ALBUMARTIST%,,' & & ',' & ')')',)**

From:  
ALBUMARTIST = ddd  
ARTIST(mv) = aaa bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh iii  
To:  
Result = ddd (feat. aaa bbb & ccc & eee & fff & ggg & hhh iii)

DD.20111214.1045.CET

---

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [December 15, 2011, 10:16pm UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/3 "2011-12-15T22:16:21Z")

</div>

> [@DetlevD](#):
>
> The scripting expression looks like as if there are too much round brackets and commas involved (slipping through the export scripting syntax checker).

I copy/pasted the script as-is. Where can I find the syntax checker (didn't know about that)?

> [@DetlevD](#):
>
> And what sense have ARTIST and ALBUM ARTIST in this script?

Well, I think it's a matter how people tag their music. Here, ordinary CDs have an ARTIST but no ALBUM ARTIST. Only, when there are tracks on the CD that feature more than one artist, the ALBUM ARTIST is given. In case of samplers it's easy (Various Artists). For standard albums, the `main' artist is chosen to fill the ALBUM ARTIST field. Then, this name appears as ARTIST as well as ALBUM ARTIST for all tracks of the entire album. I guess, this was already known ...

# Now, I'd like to export in the following way, for example: ==Album from singer Peter== 01 - Intro 02 - A wonderful song 03 - A duet (feat. some other artist named Paul) 04 - More music 05 - Medley (feat. Sandra, Paul & Josh)

That means, all ARTISTs shall be printed except ALBUM ARTIST. Moreover, I want to have the comma (,) as a separator except for the last two in the list (feat. artist 1, artist 2, artist 3 & artist 4).

This should work regardless of the order of the ARTIST fields in the file (I guess, not tested, your code won't work, when `ddd' is the first ARTIST) and hopefully also for artist with & in their name (Kool & The Gang, Kc & JoJo, Kruder & Dorfmeister, ...).

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 16, 2011, 3:33am UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/4 "2011-12-16T03:33:19Z")

</div>

> [@LosMintos](#):
>
> I copy/pasted the script as-is. Where can I find the syntax checker (didn't know about that)?

Hmm, isn't there something implemented in Mp3tag behind the scene, invisible to the user?

> [@LosMintos](#):
>
> # ... Now, I'd like to export in the following way, for example: ==Album from singer Peter== 01 - Intro 02 - A wonderful song 03 - A duet (feat. some other artist named Paul) 04 - More music 05 - Medley (feat. Sandra, Paul & Josh)
> 
> That means, all ARTISTs shall be printed except ALBUM ARTIST. Moreover, I want to have the comma (,) as a separator except for the last two in the list (feat. artist 1, artist 2, artist 3 & artist 4).  
> This should work regardless of the order of the ARTIST fields in the file ...

You can change the separator parameter in the function $meta\_sep() as you will.  
A following function $regexp() can change the last comma into an ampersand.  
This type of request has been solved already.  
Try to search harder in the forum posts. There are one or more solutions to find.  
[http://www.google.de/search?q=site%3Aforum...e%20%24meta\_sep](http://www.google.de/search?q=site%3Aforums.mp3tag.de%20%24meta_sep)

> [@LosMintos](#):
>
> ... (I guess, not tested, your code won't work, when `ddd' is the first ARTIST) and hopefully also for artist with & in their name (Kool & The Gang, Kc & JoJo, Kruder & Dorfmeister, ...).

Well, you are right with your opinion, when you relate on your first request in this thread.  
And we note that the wish and the problem has not been sufficiently thought through in the first step.

You can try this ...

**%ALBUMARTIST%$iflonger($meta(ARTIST,1),0,' (feat. '$cutRight($replace($meta\_sep(ARTIST,' & ')' & ',%ALBUMARTIST%' & ',),$len(' & '))')',)**

From:  
ALBUMARTIST = ddd  
ARTIST(mv) = aaa bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh iii  
To:  
Result = ddd (feat. aaa bbb & ccc & eee & fff & ggg & hhh iii)

From:  
ALBUMARTIST = aaa bbb  
ARTIST(mv) = aaa bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh iii  
To:  
Result = aaa bbb (feat. ccc & ddd & eee & fff & ggg & hhh iii)

From:  
ALBUMARTIST = hhh iii  
ARTIST(mv) = aaa bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh iii  
To:  
Result = hhh iii (feat. aaa bbb & ccc & ddd & eee & fff & ggg)

You can try this ...

**%ALBUMARTIST%$iflonger($meta(ARTIST,1),0,' (feat. '$regexp($cutRight($replace($meta(ARTIST)', ',%ALBUMARTIST%', ',),$len(', ')),'^(.+),(.+)$','$1 &$2')')',)**

From:  
ALBUMARTIST = hhh & iii  
ARTIST(mv) = aaa & bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh & iii  
To:  
Result = hhh & iii (feat. aaa & bbb, ccc, ddd, eee, fff & ggg)

From:  
ALBUMARTIST = ggg  
ARTIST(mv) = aaa & bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh & iii  
To:  
Result = ggg (feat. aaa & bbb, ccc, ddd, eee, fff & hhh & iii)

DD.20111216.0534.CET  
Edit.DD.20111216.2055.CET

---

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [December 16, 2011, 10:38pm UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/5 "2011-12-16T22:38:24Z")

</div>

Hi,

> [@DetlevD](#):
>
> You can change the separator parameter in the function $meta\_sep() as you will.  
> A following function $regexp() can change the last comma into an ampersand.  
> This type of request has been solved already.  
> Try to search harder in the forum posts. There are one or more solutions to find.

You're right, I should have searched at first. Unfortunately, even with your hints I was not able to find this ready-made solution. (Probably there's some magic with $reverse() or the like included?).

However, my approach, looking for the positions of the `magic' char --- $char(7) used as separator, cutting the string from left and right, and finally put together, is for sure ugly ;-), but working.

> [@DetlevD](#):
>
> You can try this ...
> 
> **%ALBUMARTIST%$iflonger($meta(ARTIST,1),0,' (feat. '$regexp($cutRight($replace($meta(ARTIST)', ',%ALBUMARTIST%', ',%DUMMY%),$len(', ')),'^(.+),(.+)$','$1 &$2')')',%DUMMY%)**

I appreciate your help, but it's not working for me. But your advice to escape (feat. etc. with ' makes the code a bit more readable.

> [@DetlevD](#):
>
> From:  
> ALBUMARTIST = hhh & iii  
> ARTIST(mv) = aaa & bbb\\ccc\\ddd\\eee\\fff\\ggg\\hhh & iii  
> To:  
> Result = hhh & iii (feat. aaa & bbb, ccc, ddd, eee, fff & ggg)

I get  
(feat. aaa & bbbcccdddeeefffggghhh & i)

I don't know, what's wrong there ...

There's a slightly improved version of my approach. Code's a bit cleaner ![:unsure:](https://community.mp3tag.de/uploads/default/original/1X/cfaeba84fe6704387c5b34dfdd8172bd51b6f533.gif ":unsure:") and there are tests for empty ALBUM ARTIST and for the case that %album artist% is not in the list of %artist%'s.

I added some linebreaks for readability. Of course they also appear in the output, but they can be removed.

```
$filename($getEnv('TEMP')\mp3tagexporttest.txt,utf-8)
$loop(%album%)
$loop(%discnumber%)$loop(%track%)%tracknumber% - %title%
$if(%album artist%,
$iflonger($meta(artist,1),0,
    $if($eql($strchr($meta(artist),%album artist%),0),
        $puts(l,$len('(feat. '$meta_sep(artist,$char(7)')')))
        $puts(cl,$strrchr('(feat. '$meta_sep(artist,$char(7))')',$char(7)))
        $puts(cf,$strchr('(feat. '$meta_sep(artist,$char(7))')',$char(7)))
        $if($eql($get(cl),$get(cf)),
            '(feat. '$meta_sep(artist,' & ')')',
            $replace($cutRight('(feat. '$meta_sep(artist,$char(7))')',$add($sub($get(l),$get(cl)),1))' & '$cutLeft('(feat. '$meta_sep(artist,$char(7))')',$get(cl)),$char(7),', '))
        ,
        $puts(l,$len('(feat. '$replace($meta_sep(artist,$char(7)),%album artist%,)')'))
        $puts(cl,$strrchr('(feat. '$replace($meta_sep(artist,$char(7)),%album artist%,)')',$char(7)))
        $puts(cf,$strchr('(feat. '$replace($meta_sep(artist,$char(7)),%album artist%,)')',$char(7)))
        $if($eql($get(cl),$get(cf)),
            '(feat. '$replace($meta_sep(artist,$char(7)),%album artist%,,$char(7),)')',
            $replace($regexp($cutRight('(feat. '$replace($meta_sep(artist,$char(7)),%album artist%,)')',$add($sub($get(l),$get(cl)),1)),($char(7))(.*),$2)' & '$cutLeft('(feat. '$replace($meta_sep(artist,$char(7)),%album artist%,)')',$get(cl)),$char(7),', ')))
        ,
        ' no feature')
        ,' no album artist')
$loopend()
$loopend()
$loopend()

```

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 17, 2011, 2:24am UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/6 "2011-12-17T02:24:51Z")

</div>

> [@LosMintos](#):
>
> ... I appreciate your help, but it's not working for me. But your advice to escape (feat. etc. with ' makes the code a bit more readable.  
> I get  
> (feat. aaa & bbbcccdddeeefffggghhh & i)  
> I don't know, what's wrong there ...

See attached picture, which shows the expression working as designed.

**%ALBUMARTIST%$iflonger($meta(ARTIST,1),0,' (feat. '$regexp($cutRight($replace($meta(ARTIST)', ',%ALBUMARTIST%', ',),$len(', ')),'^(.+),(.+)$','$1 &$2')')',)**

 ![](https://community.mp3tag.de/uploads/default/original/2X/4/431a933c86ff2b7c78233f4ea21a0aaa998828d6.png)  

DD.20111217.0425.CET

 ![](https://community.mp3tag.de/uploads/default/original/2X/4/431a933c86ff2b7c78233f4ea21a0aaa998828d6.png)

---

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [December 17, 2011, 11:01am UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/7 "2011-12-17T11:01:47Z")

</div>

Are you sure that you have real multivalue fields in the MP3? Perhaps there's a differene in handling MP3 and FLAC? I don't know what's going on ...

 ![](https://community.mp3tag.de/uploads/default/original/2X/a/ae16731030b121e8805daeffc44d0a3f370c19c3.png)  

 ![](https://community.mp3tag.de/uploads/default/original/2X/a/ae16731030b121e8805daeffc44d0a3f370c19c3.png)

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 17, 2011, 11:11am UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/8 "2011-12-17T11:11:06Z")

</div>

> [@LosMintos](#):
>
> Are you sure that you have real multivalue fields in the MP3? Perhaps there's a differene in handling MP3 and FLAC? I don't know what's going on ...

Please check the difference spelling of ...  
%ALBUMARTIST%  
%ALBUM ARTIST%

DD.20111217.1312.CET

---

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [December 18, 2011, 5:22pm UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/9 "2011-12-18T17:22:15Z")

</div>

> [@DetlevD](#):
>
> Please check the difference spelling of ...  
> %ALBUMARTIST%  
> %ALBUM ARTIST%

Oh, stupid! Now, it's working, and I understand the tricks. Very nice!! Thank you very much!

---

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [December 18, 2011, 5:39pm UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/10 "2011-12-18T17:39:38Z")

</div>

I'm impressed, Detlev D.! Thanks again. I made a little modification to check first for an existing ALBUM ARTIST field and then used again $char(7) to handle artists with comma ',' in their name (10,000 Manicas as an example). There might be a litte confusion with artist with an & in their name, but life's never perfect 🙂

```
$if(%ALBUM ARTIST%,$iflonger($meta(ARTIST,1),0,' (feat. '$replace($regexp($cutRight($replace($meta_sep(ARTIST,$char(7))$char(7),%ALBUM ARTIST%$char(7),%DUMMY%),$len($char(7))),'^(.+)'$char(7)'(.+)$','$1 & $2'),$char(7),', ')')',%DUMMY%),%DUMMY%)
```

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 21, 2011, 6:27am UTC](https://community.mp3tag.de/t/convert-multivalue-artist-field-to-a-featuring-list-with-respect-to-album-artist/12810/11 "2011-12-21T06:27:38Z")

</div>

> [@LosMintos](#):
>
> I'm impressed, Detlev D.! Thanks again. I made a little modification to check first for an existing ALBUM ARTIST field and then used again $char(7) to handle artists with comma ',' in their name (10,000 Manicas as an example). There might be a litte confusion with artist with an & in their name, but life's never perfect 🙂 ...

LosMintos, well done, nevertheless, it works!

**Expression**

**%ALBUMARTIST%$if(%ALBUMARTIST%,$iflonger($meta(ARTIST,1),0,' (feat. '$replace($regexp($cutRight($replace($meta\_sep(ARTIST,$char(7))$char(7),%ALBUMARTIST%$char(7),),$len($char(7))),'^(.+)'$char(7)'(.+)$','$1 & $2'),$char(7),', ')')',),)**

... or somewhat reduced ...

**%ALBUMARTIST%$if(%ALBUMARTIST%,$iflonger($meta(ARTIST,1),0,' (feat. '$replace($regexp($cutRight($replace($meta\_sep(ARTIST,$char(7))$char(7),%ALBUMARTIST%$char(7),),1),'^(.+)\7(.+)$','$1 & $2'),$char(7),', ')')',),)**

**Examples**  
From:  
ALBUMARTIST = ddd  
ARTIST(mv) = aaa & bbb\\ccc\\ddd\\e,e,e\\fff\\ggg\\hhh & iii  
To:  
Result = ddd (feat. aaa & bbb, ccc, e,e,e, fff, ggg & hhh & iii)

From:  
ALBUMARTIST = e,e,e  
ARTIST(mv) = aaa & bbb\\ccc\\ddd\\e,e,e\\fff\\ggg\\hhh & iii  
To:  
Result = e,e,e (feat. aaa & bbb, ccc, ddd, fff, ggg & hhh & iii)

From:  
ALBUMARTIST = hhh & iii  
ARTIST(mv) = aaa & bbb\\ccc\\ddd\\e,e,e\\fff\\ggg\\hhh & iii  
To:  
Result = hhh & iii (feat. aaa & bbb, ccc, ddd, e,e,e, fff & ggg)

From:  
ALBUMARTIST =   
ARTIST(mv) = aaa & bbb\\ccc\\ddd\\e,e,e\\fff\\ggg\\hhh & iii  
To:  
Result =

DD.20111221.0843.CET
