Albumartist problem

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

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

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

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

Yes, I already wrote that:

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.

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

without showing the real code.

1 Like

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.

Some whitespace added for readability:

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.

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

or

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

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

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

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

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.

1 Like

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.

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

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