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

I’m looking at improving my MusicBee artist script 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 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 the %_artists_track_all_std_multi% value given by AAV.

I’m wondering if $foreach 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:

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

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

[' & ', ' 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)

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

$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%)
          )
        )
      )
    )
  )
)
3 Likes

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~ :sunglasses: :call_me_hand:

1 Like

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:

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

with something like:

$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 :wink:).

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~ :blue_heart: (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~