Can't get total albums script to work


#1

I've spent hours on this. :frustration: After I finally figured out that, for some un-Godly reason, %track% and %_total% return tracknumbers in different formats, I'm still running into problems. Basically, I want this loop to sort by album, and increment a counter variable everytime it finds a complete album, this telling me how many complete albums I have in any folder.

Here's my code (carriage returns are entered in for readability):

List compiled by %_app%
Updated:'['COLOR="Blue"']'%_date%'['/COLOR']'
$puts(no_albums,0)
$loop(%album%)
$if($eql($left(%track%,2),%_total%),$puts(no_albums,$add(1,$get(no_albums))),)
$loopend()
Added:

'['COLOR="Blue"']''['SIZE="5"']'MUSIC'['/COLOR']' - '['COLOR="Red"']'$get(no_albums) Albums'['/COLOR']' and change

For some reason, it outputs zero, even though when change $puts to $put it returns numbers other than zero. Even this is weird. I was testing it on an folder with 2 albums and a single track in it. The count it should have returned while looping was 1, 2. It returned 1, 2, 6. I have NO idea where that 6 is coming from, especially since no_albums can only be increased by one and that output occurs EVERYTIME that function is called.

So, not only is the function being magically called a 3rd time, it's also being increased magically by 4. Can anyone help?!? Argghghg.


#2
List compiled by %_app%
Updated:'['COLOR="Blue"']'%_date%'['/COLOR']'
$loop(%album%)

$puts(no_albums,$if(%track%,$if($eql($num(%track%,2),$num(%_total%,2)),$add(1,$get(no_albums)),$get(no_albums)),$get(no_albums)))

$loopend()

and don't use $puts(no_albums,0)


#3
QUOTE (dano @ Sep 18 2006, 06:02) <{POST_SNAPBACK}>
List compiled by %_app%
Updated:'['COLOR="Blue"']'%_date%'['/COLOR']'
$loop(%album%)

$puts(no_albums,$if(%track%,$if($eql($num(%track%,2),$num(%_total%,2)),$add(1,$get(no_albums)),$get(no_albums)),$get(no_albums)))

$loopend()

and don't use $puts(no_albums,0)

Thanks, that works, but . . . could someone perhaps explain to me why that code works and what I was using didn't? I mean, I mostly get why yours works. You make sure to update the variable everytime through the loop, either with a new value or the previous one. But that $if(%track%... statement confuses me. How does that make the distinction between a file that is part of an album and a file that isn't? The way that I have my media library set up it's probably not gonna matter, but in this case the program is sure execute that then statement for every single one of my 4100+ mp3s instead of saving some processing power by skipping over the ones that it knows are not part of an album.

Mostly, I'm confused about why my code doesn't work . . .