IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Convert multivalue artist field to a featuring list with respect to album artist, Feel free to shorten the code :-)
LosMintos
post Dec 13 2011, 15:23
Post #1


Member


Group: Full Members
Posts: 88
Joined: 23-September 08
Member No.: 7617
Mp3tag Version: 2.51



Dear all,

yesterday some guys bailed me out with nice tricks (in German: http://forums.mp3tag.de/index.php?showtopic=14824) 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
QUELLTEXT
ALBUM ARTIST=2Pac
ARTIST=2Pac
ARTIST=Dr. Dre
ARTIST=Roger Troutman


The following export script
QUELLTEXT
$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
ZITAT
(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.gif
Go to the top of the page
 
+Quote Post
DetlevD
post Dec 14 2011, 09:20
Post #2


Member


Group: Full Members
Posts: 4896
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



QUOTE (LosMintos @ Dec 13 2011, 15:23) *
Dear all, yesterday some guys bailed me out with nice tricks (in German: http://forums.mp3tag.de/index.php?showtopic=14824) 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

This post has been edited by DetlevD: Apr 24 2014, 10:12


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
LosMintos
post Dec 16 2011, 00:16
Post #3


Member


Group: Full Members
Posts: 88
Joined: 23-September 08
Member No.: 7617
Mp3tag Version: 2.51



ZITAT(DetlevD @ Dec 14 2011, 09:20) *
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)?

ZITAT(DetlevD @ Dec 14 2011, 09:20) *
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, ...).

Go to the top of the page
 
+Quote Post
DetlevD
post Dec 16 2011, 05:33
Post #4


Member


Group: Full Members
Posts: 4896
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



QUOTE (LosMintos @ Dec 16 2011, 00:16) *
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?

QUOTE (LosMintos @ Dec 16 2011, 00:16) *
...
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

QUOTE (LosMintos @ Dec 16 2011, 00:16) *
... (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

This post has been edited by DetlevD: Apr 24 2014, 10:18


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
LosMintos
post Dec 17 2011, 00:38
Post #5


Member


Group: Full Members
Posts: 88
Joined: 23-September 08
Member No.: 7617
Mp3tag Version: 2.51



Hi,

ZITAT(DetlevD @ Dec 16 2011, 05:33) *
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.


ZITAT(DetlevD @ Dec 16 2011, 05:33) *
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.

ZITAT(DetlevD @ Dec 16 2011, 05:33) *
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.gif 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.
QUELLTEXT
$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()
Go to the top of the page
 
+Quote Post
DetlevD
post Dec 17 2011, 04:24
Post #6


Member


Group: Full Members
Posts: 4896
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



QUOTE (LosMintos @ Dec 17 2011, 00:38) *
... 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')')',)
Attached Image


DD.20111217.0425.CET

This post has been edited by DetlevD: Apr 24 2014, 10:18


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
LosMintos
post Dec 17 2011, 13:01
Post #7


Member


Group: Full Members
Posts: 88
Joined: 23-September 08
Member No.: 7617
Mp3tag Version: 2.51



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

Attached Image
Go to the top of the page
 
+Quote Post
DetlevD
post Dec 17 2011, 13:11
Post #8


Member


Group: Full Members
Posts: 4896
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



QUOTE (LosMintos @ Dec 17 2011, 13:01) *
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


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
LosMintos
post Dec 18 2011, 19:22
Post #9


Member


Group: Full Members
Posts: 88
Joined: 23-September 08
Member No.: 7617
Mp3tag Version: 2.51



ZITAT(DetlevD @ Dec 17 2011, 13:11) *
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!
Go to the top of the page
 
+Quote Post
LosMintos
post Dec 18 2011, 19:39
Post #10


Member


Group: Full Members
Posts: 88
Joined: 23-September 08
Member No.: 7617
Mp3tag Version: 2.51



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

QUELLTEXT
$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%)
Go to the top of the page
 
+Quote Post
DetlevD
post Dec 21 2011, 08:27
Post #11


Member


Group: Full Members
Posts: 4896
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



QUOTE (LosMintos @ Dec 18 2011, 19:39) *
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),'^(.+)\x07(.+)$','$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 = <nothing>
ARTIST(mv) = aaa & bbb\\ccc\\ddd\\e,e,e\\fff\\ggg\\hhh & iii
To:
Result = <nothing>

DD.20111221.0843.CET

This post has been edited by DetlevD: Apr 24 2014, 10:20


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 31st August 2014 - 07:16