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


#1

Dear all,

yesterday some guys bailed me out with nice tricks (in German: /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

.

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:


#2

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


#3

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

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, ...).


#4

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

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

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


#5

Hi,

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.

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 ...

There's a slightly improved version of my approach. Code's a bit cleaner :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()

#6

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


DD.20111217.0425.CET



#7

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 ...




#8

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

DD.20111217.1312.CET


#9

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


#10

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 :slight_smile:

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

#11

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