# Trying to figure out how to handle featured artists differently than primary artists

**URL:** <https://community.metabrainz.org/t/trying-to-figure-out-how-to-handle-featured-artists-differently-than-primary-artists/659378>\
**Category:** MusicBrainz Picard\
**Tags:** featured-artists, taggerscript, picard, additional-artist-variables\
**Created:** [October 11, 2023, 4:28am UTC](https://community.metabrainz.org/t/trying-to-figure-out-how-to-handle-featured-artists-differently-than-primary-artists/659378 "2023-10-11T04:28:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![UltimateRiff](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ultimateriff/32/47799_2.png) [@UltimateRiff](https://community.metabrainz.org/u/UltimateRiff)\
**Post date:** [October 11, 2023, 4:28am UTC](https://community.metabrainz.org/t/trying-to-figure-out-how-to-handle-featured-artists-differently-than-primary-artists/659378/1 "2023-10-11T04:28:23Z")

</div>

I’m looking at improving my [MusicBee artist script](https://community.metabrainz.org/t/musicbee-taggerscript-for-standardizing-artists-and-setting-display-artist/619244) by sending primary (non-featured) artists to one tag `%artist%`, and featured artists to a different tag `%guest artist%`

(for context, I’m using the [Additional Artist Variables](https://github.com/rdswift/picard-plugins/blob/2.0_RDS_Plugins/plugins/additional_artists_variables/docs/README.md) plugin by @rdswift)

I’ve been looking through the Picard documentation, and I can’t seem to find a way to get the index of a given value, say any of `feat.; featuring; with; prod.; [etc.]` in `%_artists_track_all_join_phrases%`. once I can get that, I figure I could [`$slice`](https://picard-docs.musicbrainz.org/v2.9/en/functions/func_slice.html) the `%_artists_track_all_std_multi%` value given by AAV.

I’m wondering if [`$foreach`](https://picard-docs.musicbrainz.org/v2.9/en/functions/func_foreach.html) might be the way to go, but I can’t quite wrap my brain around how that works at the moment…

* * *

I’m doing it this way instead of with the `_artists_track_primary...` and `_artists_track_additional...` variables, because I want it to be able to handle artist fields where there’s multiple non-featured artists like this example:

[https://musicbrainz.org/recording/6a6518be-7500-44e6-af8b-30e0aee2bb6f](https://musicbrainz.org/recording/6a6518be-7500-44e6-af8b-30e0aee2bb6f)

…and also handle multiple types of features, like below (`%guest artist%` would be `lil aquafina; Aaron Kates`)

[https://musicbrainz.org/recording/b9bfcca9-7fd9-4f35-8755-1816f6a82d12](https://musicbrainz.org/recording/b9bfcca9-7fd9-4f35-8755-1816f6a82d12)

for reference, according to the View script variables plugin, the values of `%_artists_track_all_join_phrases%` for the above tracks are respectively:

```auto
[' & ', ' feat. ', '\u200b']
[' feat. ', ' prod. ', '\u200b']

```

(no, I don’t know why the last join phrase is a zero-width space, it’s almost certainly not another plugin or script of mine)

---

<div class="post-metadata">

**Author:** ![rdswift](https://community.metabrainz.org/user_avatar/community.metabrainz.org/rdswift/32/7032_2.png) [@rdswift](https://community.metabrainz.org/u/rdswift)\
**Post date:** [October 11, 2023, 6:17pm UTC](https://community.metabrainz.org/t/trying-to-figure-out-how-to-handle-featured-artists-differently-than-primary-artists/659378/2 "2023-10-11T18:17:50Z")

</div>

Try the following in a tagger script (not the renaming script) and see if it allows you to do what you want:

```taggerscript
$noop(=======================================================================

This script splits the track artists into main artists and guest artists
based on whether the artist appears before or after a join phrase containing
'feat'. It creates the following new tags and variables based on the artist
names as credited.

  %_main_artists% multi-value containing the main artists' names
  %_guest_artists% multi-value containing the guest artists' names
  %main_artists% tag containing the main artists separated by join phrases
  %guest_artists% tag containing the guest artists separated by join phrases

Join phrases of a zero-length space in the %main_artists% and %guest_artists%
tags are replaced with a blank (empty) join phrase.

=============================================================================)
$set(_idx,)
$set(main_artists,%_artists_track_all_cred%)
$setmulti(_main_artists,%_artists_track_all_cred_multi%)
$foreach(%_artists_track_all_join_phrases%,$if($in($lower(%_loop_value%),feat),$set(_idx,%_loop_count%)))
$if(%_idx%,
  $noop( "feat" found in join phrases )
  $noop( Set main and guest artists multi-values )
    $setmulti(_main_artists,$slice(%_artists_track_all_cred_multi%,0,%_idx%))
    $setmulti(_guest_artists,$slice(%_artists_track_all_cred_multi%,%_idx%))
  $noop( Set main and guest artists display tags )
    $set(main_artists,)
    $foreach(%_artists_track_all_cred_multi%,
      $set(_join_phrase,$getmulti(%_artists_track_all_join_phrases%,$sub(%_loop_count%,1)))
      $if($eq(%_join_phrase%,\u200b),$set(_join_phrase,))
      $noop( Append to appropriate artist type tag )
      $noop( Identify artist type )
        $if($lte(%_loop_count%,%_idx%),
        $noop( Main artist )
          $set(main_artists,%main_artists%%_loop_value%)
          $if($lt(%_loop_count%,%_idx%),
          $noop( Add join phrase )
            $set(main_artists,%main_artists%%_join_phrase%)
          )
        ,
        $noop( Guest artist )
          $set(guest_artists,%guest_artists%%_loop_value%)
          $if($lt(%_loop_count%,%_artists_track_all_count%),
          $noop( Add join phrase )
            $set(guest_artists,%guest_artists%%_join_phrase%)
          )
        )
      )
    )
  )
)

```

---

<div class="post-metadata">

**Author:** ![UltimateRiff](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ultimateriff/32/47799_2.png) [@UltimateRiff](https://community.metabrainz.org/u/UltimateRiff)\
**Post date:** [October 11, 2023, 7:41pm UTC](https://community.metabrainz.org/t/trying-to-figure-out-how-to-handle-featured-artists-differently-than-primary-artists/659378/3 "2023-10-11T19:41:07Z")

</div>

that looks like it’ll work great (with a few minor adjustments to include ft., featuring, etc.), I’ll try it out this evening once I’m back at my PC~

thank you for your script magic, my dude~ 🕶 🤙

---

<div class="post-metadata">

**Author:** ![rdswift](https://community.metabrainz.org/user_avatar/community.metabrainz.org/rdswift/32/7032_2.png) [@rdswift](https://community.metabrainz.org/u/rdswift)\
**Post date:** [October 11, 2023, 11:30pm UTC](https://community.metabrainz.org/t/trying-to-figure-out-how-to-handle-featured-artists-differently-than-primary-artists/659378/4 "2023-10-11T23:30:44Z")

</div>

> [@UltimateRiff](#):
>
> that looks like it’ll work great (with a few minor adjustments to include ft., featuring, etc.),

By using the `$in()` function to check for ‘feat’, it will also match ‘feat.’, ‘featuring’ and so on. If you also want to catch ‘ft’ and ‘ft.’ you would replace the line:

```taggerscript
$foreach(%_artists_track_all_join_phrases%,$if($in($lower(%_loop_value%),feat),$set(_idx,%_loop_count%)))

```

with something like:

```taggerscript
$foreach(%_artists_track_all_join_phrases%,$set(_test_phrase,$lower(%_loop_value%))$if($or($in(%_test_phrase%,feat),$in(%_test_phrase%,ft)),$set(_idx,$if2(%_idx%,%_loop_count%))))

```

Note that I haven’t tested this change, so you may have to tweak it a bit to match your situation (or make it work 😉).

---

<div class="post-metadata">

**Author:** ![UltimateRiff](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ultimateriff/32/47799_2.png) [@UltimateRiff](https://community.metabrainz.org/u/UltimateRiff)\
**Post date:** [October 12, 2023, 1:31am UTC](https://community.metabrainz.org/t/trying-to-figure-out-how-to-handle-featured-artists-differently-than-primary-artists/659378/5 "2023-10-12T01:31:24Z")

</div>

okay, so as-is, the script you wrote removes the spaces between the artist names and join phrases for `%main_artists%` and `%guest_artists%`\*. I don’t foresee me using these values for my script as I’ll be using the multi-value tags, but for anyone else looking to use these tags, that could be an issue… apart from that, it’s perfect~ I can prolly work it towards my use case from here~ 💙 (and I’ll of course post the resulting script over on the other thread linked in the OP)

\*`%main_artists%` for the first example became `Antoine Dodson&The Gregory Brothers` and `%guest_artists%` for the second example is `lil aquafinaprod.aaron kates`

edit: I also had to remove the parentheses in the `$noop()` at the beginning… lol

edit 2: posted [here](https://community.metabrainz.org/t/musicbee-ver-2-available-taggerscript-for-standardizing-artists-and-setting-display-artist/619244/4)~
