# Albumartist problem

**URL:** <https://community.mp3tag.de/t/albumartist-problem/53148>\
**Category:** Support\
**Created:** [May 8, 2021, 5:55pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148 "2021-05-08T17:55:28Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![g.p.m](https://community.mp3tag.de/user_avatar/community.mp3tag.de/g.p.m/32/343_2.png) [@g.p.m](https://community.mp3tag.de/u/g.p.m)\
**Post date:** [May 8, 2021, 5:55pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/1 "2021-05-08T17:55:28Z")

</div>

I'm putting together some export scripts and I'm struggling at one particular point:  
Albumartist vs. Artist.

Case 1: There is a sampler album, in which there might be or not an album artist (e.g. Various Artists) and given for each track a separate artist. Then the artist of each track in the exported file should be different.

Case 2: There is one album of one artist (and the same as album artist, or none) in which case the artist in the exported file should obviously be this very artist.

I wanted to have one universal script which handles all of this, because I don't know or don't want to care of the above possibilities.

In the header of the export file I want to see the artist or, if it's a sampler, VA.

`$if(%albumartist%,$if($eql(%albumartist%,%artist%),%artist%,'VA'),%artist%)`

i.e.:  
$if(  
%albumartist%  
, $if(  
$eql(%albumartist%,%artist%)  
, %artist%  
,' VA'  
)  
, %artist%  
)

This works just fine.

For the track listing part my approach so far was an if-loop as similar.  
Notice: the structure of the if-loop is the same as the above.  
I'm using a $loop(%\_filename\_ext%) here.

`$if(%albumartist%,$if($eql(%albumartist%,%artist%),$puts(at,%title%),$puts(at,%artist%: %title%)),$puts(at,%title%))`

i.e.  
$if(  
%albumartist%  
, $if  
(  
$eql(%albumartist%,%artist%)  
, $puts(at,%title%)  
, $puts(at,%artist%: %title%)  
)  
, $puts(at,%title%)  
)

which I believe means I get variable 'at' either containing only 'title' or 'artist: title'.  
I'd then use this variable 'at' further in the script.

Problem is: It doesn't work this way and I can't figure out what's wrong with my script.  
It doesn't work either when I put the fieldnames in instead of the $puts().

To compare this I give too examples:

File 1 tags:  
Track: 8  
Title: Summer  
Artist: Calvin Harris  
Albumartist: Various (could also be none)  
Length: 03:45

Exports as:  
08 - Summer ..................... 03:45  
Should be:  
08 - Calvin Harris: Summer ...... 03:45

File 2 tags:  
Track: 8  
Title: The Lily  
Artist: Layla Zoe  
Albumartist: none (could also be 'Layla Zoe')

Exports as:  
08 - The Lily ................... 10:11  
This one's right.

I'd highly appreciate if someone could look at this and point me into the right direction.  
As reward I might post the final working export script 🙂

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [May 8, 2021, 8:25pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/2 "2021-05-08T20:25:41Z")

</div>

I think that the $put() variables are only available inside a $loop(). as soon as that ends, the variable is gone.  
So perhaps a little more about the environment...

---

<div class="post-metadata">

**Author:** ![g.p.m](https://community.mp3tag.de/user_avatar/community.mp3tag.de/g.p.m/32/343_2.png) [@g.p.m](https://community.mp3tag.de/u/g.p.m)\
**Post date:** [May 8, 2021, 9:36pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/3 "2021-05-08T21:36:28Z")

</div>

Thanks for looking into it.  
I've noticed that behavior of the $put() and $puts() before and considered it  
In fact I'm using it in a loop:

`$loop(%_filename_ext%)$if(%albumartist%,$if($eql(%albumartist%,%artist%),$puts(at,%title%),$puts(at,%artist%: %title%')),$puts(at,%title%))... ...$loopend())`

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [May 9, 2021, 7:24am UTC](https://community.mp3tag.de/t/albumartist-problem/53148/4 "2021-05-09T07:24:01Z")

</div>

$puts() assigns a value "silently", so without screen output. Do you output %at% somewhere? As right now it is simply an assignment of values to a variable.

---

<div class="post-metadata">

**Author:** ![g.p.m](https://community.mp3tag.de/user_avatar/community.mp3tag.de/g.p.m/32/343_2.png) [@g.p.m](https://community.mp3tag.de/u/g.p.m)\
**Post date:** [May 9, 2021, 6:25pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/5 "2021-05-09T18:25:12Z")

</div>

Yes, I already wrote that:

> [@g.p.m](#):
>
> which I believe means I get variable 'at' either containing only 'title' or 'artist: title'.  
> I'd then use this variable 'at' further in the script.

---

<div class="post-metadata">

**Author:** ![g.p.m](https://community.mp3tag.de/user_avatar/community.mp3tag.de/g.p.m/32/343_2.png) [@g.p.m](https://community.mp3tag.de/u/g.p.m)\
**Post date:** [May 10, 2021, 7:18pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/6 "2021-05-10T19:18:18Z")

</div>

Since the puts() function inside the if-loop didn't work reliably I've tried the opposite -  
put the if-loop inside the puts():

instead of  
`$if(%albumartist%,$if($eql(%albumartist%,%artist%),$puts(at,%title%),$puts(at,%artist%: %title%)),$puts(at,%title%))`  
i.e.  
$if(  
%albumartist%  
, $if  
($eql(%albumartist%,%artist%)  
, $puts(at,%title%)  
, $puts(at,%artist%: %title%)  
)  
, $puts(at,%title%)  
)

I used now:

`$puts(at,$if($eql(%albumartist%,%artist%),%title%,%artist%: %title%))`  
i.e.  
$puts(at,  
$if(  
$eql(%albumartist%,%artist%)  
,%title%  
,%artist%: %title%)  
)

This finally seems to work. It's easier, too, but boy, how much time it took me to figure this one out.

Conclusion:  
puts() doesn't work reliably inside if-loops (if at all).  
get() seems to work fine, though.

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [May 10, 2021, 8:18pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/7 "2021-05-10T20:18:29Z")

</div>

Good if you found a solution.  
Yet, it is rather bold to claim that $puts()

> [@g.p.m](#):
>
> doesn't work reliably

without showing the real code.

---

<div class="post-metadata">

**Author:** ![g.p.m](https://community.mp3tag.de/user_avatar/community.mp3tag.de/g.p.m/32/343_2.png) [@g.p.m](https://community.mp3tag.de/u/g.p.m)\
**Post date:** [May 10, 2021, 11:41pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/8 "2021-05-10T23:41:42Z")

</div>

No offense. I see your point.  
The not working code was in my first post, by the way.  
I'm still working on it and will show you, of course. Won't fill the forum with rubbish.  
Thing is: **inside if-loop**.  
I'm not satisfied yet.

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [May 11, 2021, 6:25am UTC](https://community.mp3tag.de/t/albumartist-problem/53148/9 "2021-05-11T06:25:40Z")

</div>

Some whitespace added for readability:

> [@g.p.m](#):
>
> ```auto
> $loop(%_filename_ext%)
> $if(%albumartist%,
> $if($eql(%albumartist%,%artist%),
> $puts(at,%title%),
> $puts(at,%artist%: %title%')
> ),$puts(at,%title%)
> )
> …
> $loopend()
> )
> 
> ```

There is an extra closing parenthesis dangling at the end, so I suppose there is some context that we are not seeing which may explain the unexpected behavior. Also, there is a single quotation mark at the end of the second `$puts()`, which is guaranteed to mess something up. (It’s missing in your subsequent code, though.)

However, I just wanted to point out that the condition could be simplified.

```auto
$if($and(%albumartist%,$neql(%albumartist%,%artist%)),
  $puts(at,%artist%: %title%'),
  $puts(at,%title%)
)

```

or

```auto
$puts(at,$if($and(%albumartist%,$neql(%albumartist%,%artist%)),
 %artist%: %title%,
 %title%
)

```

---

<div class="post-metadata">

**Author:** ![g.p.m](https://community.mp3tag.de/user_avatar/community.mp3tag.de/g.p.m/32/343_2.png) [@g.p.m](https://community.mp3tag.de/u/g.p.m)\
**Post date:** [May 11, 2021, 9:57am UTC](https://community.mp3tag.de/t/albumartist-problem/53148/10 "2021-05-11T09:57:40Z")

</div>

Thanks to both of you. My code works now as expected but I didn't get to work the $puts() inside the if-condition, though. I used the opposite - if-condition inside the $puts().

Here's the final code:

```
$filename(W:\NFO\$replace(%_workingdir%,'',`,’,`)\info_bb_c.nfo,utf-16)'[nfo][/font][b][u]'$replace(%_workingdir%,'',`,’,`)'[/u][/b]'

------------------------------------------------------------------------------$loop(%_folderpath%)
$replace($caps2($puts(aa,%albumartist%) $puts(a,%artist%) $puts(t,%title%)
Verzeichnis: %_directory%
Albumartist ...................... : $if($or($neql($get(aa),$get(a)),$eql($get(aa),'Various'),$eql($get(aa),'Various Artists'),$eql($get(aa),'Varios Artistas')),'VA',$get(a))
Album ............................ : $if2(%album%,N/A)
Genre/veroeffentlicht ............ : $if2(%genre%,N/A) '/' $if2(%year%,N/A)
Format/Bitrate/Samplerate ........ : $if2($if($eql(%_codec%,'MPEG 1 Layer III'),MP3,),$if($eql(%_codec%,'Free Lossless Audio Codec'),FLAC,)) '/' $if($eql(%_vbr%,'CBR'),%_vbr% %_bitrate% 'kbps','VBR' $loop(%_filename_ext%)$puts(Vbitrate,$add($get(Vbitrate),%_bitrate%))$puts(cnt1,$add($get(cnt1),1))$loopend()$div($get(Vbitrate),$get(cnt1)) kbps) '/' %_samplerate% Hz
Anzahl/Gesamtspielzeit/Groesse: .. : %_total_files% Tracks '/' %_total_time% h '/' %_total_size%
Cover eingebettet/Groesse ........ : $if(%_covers%,Ja [(%_cover_width%x%_cover_height%, $div(%_cover_size%,1024) KB)],Nein)),'',`,’,`)

Tracks:
$loop(%_filename_ext%)$replace($caps2($puts(at,$if($and(%albumartist%,$neql(%albumartist%,%artist%)),%artist%: %title%,%title%))$puts(rep,$sub(66,$len($mid($get(at),67,66))))$puts(rep1,$sub(66,$len($get(at))))$num(%track%,2) - $iflonger($get(at),66,$left($get(at),66)
      $mid($get(at),67,66) $repeat(.,$get(rep)),$left($get(at),66) $repeat(.,$get(rep1))) %_length%),'',`,’,`)
$loopend()------------------------------------------------------------------------------$loopend()

******************************************************************************
              Anzahl Musikdateien gesamt ...: %_total_files%
              Laenge Musikdateien gesamt ...: %_total_time% h
              Groesse Musikdateien gesamt ..: %_total_size%
******************************************************************************
 ******NFO erzeugt mit: %_app% * %_date% * http://mp3tag.de******
 ******************************************************************************

```

Screenshot: [https://i12.servimg.com/u/f12/11/74/13/27/tags10.jpg](https://i12.servimg.com/u/f12/11/74/13/27/tags10.jpg)

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [May 11, 2021, 1:44pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/11 "2021-05-11T13:44:59Z")

</div>

For maintainability, you should try to separate the definition of variables, including conditions, from their use for text output, i.e. move all `$puts()` and most `$if()` before the `$replace()`

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [May 11, 2021, 2:00pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/12 "2021-05-11T14:00:09Z")

</div>

I am pretty sure that this data is stored in %\_extension%

> [@g.p.m](#):
>
> $if2($if($eql(%\_codec%,'MPEG 1 Layer III'),MP3,),$if($eql(%\_codec%,'Free Lossless Audio Codec'),FLAC,))

or could be handled by a simple  
`$replace(%codec%,MPEG 1 Layer III,MP3,Free Lossless Audio Codec,FLAC)`  
which would avoid these rather confusing $if/$eql statements.

---

<div class="post-metadata">

**Author:** ![g.p.m](https://community.mp3tag.de/user_avatar/community.mp3tag.de/g.p.m/32/343_2.png) [@g.p.m](https://community.mp3tag.de/u/g.p.m)\
**Post date:** [May 12, 2021, 1:24pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/13 "2021-05-12T13:24:22Z")

</div>

The $replace() is on the very beginning for a reason: The site on which I use to post this has some weird behavior and I want to catch every char that breaks their BBCode, that is, also inside directory, artist, albumartist etc.

---

<div class="post-metadata">

**Author:** ![g.p.m](https://community.mp3tag.de/user_avatar/community.mp3tag.de/g.p.m/32/343_2.png) [@g.p.m](https://community.mp3tag.de/u/g.p.m)\
**Post date:** [May 12, 2021, 1:32pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/14 "2021-05-12T13:32:12Z")

</div>

Your right and I put your $replace() statement in my script.

I supplemented some formatting and color, too:

```
$filename(W:\NFO\$replace(%_workingdir%,'',`,’,`)\info_bb_c_mnv.nfo,utf-8)'[color=#9370D8][nfo][/font][b][size=3][u]'$replace(%_workingdir%,'',`,’,`)'[/u][/size][/b][/color]'

'[color=#696969] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [/color]'$loop(%_folderpath%)
$puts(col,'[color=#668033]')$puts(col1,'[color=#696969]')$puts(aa,%albumartist%)$puts(a,%artist%)$puts(t,%title%)
$get(col1)Directory: %_directory%'[/color][b]'
Albumartist'[/b]'$get(col1) ................ : '[/color]'$get(col)'[b]'$if($or($neql($get(aa),$get(a)),$eql($get(aa),'Various'),$eql($get(aa),'Various Artists'),$eql($get(aa),'Varios Artistas')),VA,$get(a))'[/color]'
Album'[/b]'$get(col1) ...................... : '[/color]'$get(col)'[b]'$if2(%album%,N/A)'[/color]'
Genre/Published'[/b]'$get(col1) ............ : '[/color]'$get(col)'[b]'$if2(%genre%,N/A) '/' $if2(%year%,N/A)'[/color]'
Codec/Bitrate/Samplerate'[/b]'$get(col1) ... : '[/color]'$get(col)'[b]'$replace(%_codec%,MPEG 1 Layer III,MP3,Free Lossless Audio Codec,FLAC) '/' $if($eql(%_vbr%,'CBR'),%_vbr% %_bitrate% kbps,VBR $loop(%_filename_ext%)$puts(Vbitrate,$add($get(Vbitrate),%_bitrate%))$puts(cnt1,$add($get(cnt1),1))$loopend()$div($get(Vbitrate),$get(cnt1)) kbps) '/' %_samplerate% Hz'[/color]'
Number/Length/Size'[/b]'$get(col1) ......... : '[/color]'$get(col)'[b]'%_total_files% Tracks '/' %_total_time% h '/' %_total_size%'[/color]'
Cover embedded/Size'[/b]'$get(col1) ........ : '[/color]'$get(col)'[b]'$if(%_covers%,Yes [(%_cover_width%x%_cover_height%, $div(%_cover_size%,1024) KB)],No)'[/color]'

Tracks:'[/b]'
$loop(%_filename_ext%)$replace($caps2($puts(on,'[color=#668033][b]')$puts(on1,'[color=#696969]')$puts(off,'[/b][/color]')$puts(at,$if($and(%albumartist%,$neql(%albumartist%,%artist%)),%artist%: %title%,%title%))$puts(rep,$sub(66,$len($mid($get(at),67,66))))$puts(rep1,$sub(66,$len($get(at))))'[b]'$num(%track%,2)'[/b]' - $iflonger($get(at),66,$get(on)$left($get(at),66)
      $mid($get(at),67,66)$get(off) $get(on1)$repeat(.,$get(rep))$get(off),$get(on)$left($get(at),66)$get(off) $get(on1)$repeat(.,$get(rep1))$get(off))),'',`,’,`) '[b]'%_length%$get(off)
$loopend()'[color=#696969] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [/color]'$loopend()

'[color=#696969] ****************************************************************************** [/color]'
'[color=#9370D8] [b]'Total number music files'[/b]' ...... : '[b]'%_total_files%' Tracks[/b][/color]'
'[color=#9370D8] [b]'Total length music files'[/b]' ...... : '[b]'%_total_time%' h [/b][/color]'
'[color=#9370D8] [b]'Total size music files'[/b]' ........ : '[b]'%_total_size%' [/b][/color]'
'[color=#696969] ****************************************************************************** [/color]'
'[color=#696969] ****NFO generated with: %_app% * %_date% * http://mp3tag.de**** [/color]' 
'[color=#696969] ****************************************************************************** [/color]'

```

screenshot: [https://i12.servimg.com/u/f12/11/74/13/27/tags11.jpg](https://i12.servimg.com/u/f12/11/74/13/27/tags11.jpg)

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [June 11, 2021, 1:33pm UTC](https://community.mp3tag.de/t/albumartist-problem/53148/15 "2021-06-11T13:33:02Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
