; mp3 alias

/MP3size {
  if (( .mp isin $right($1-,4) ) || ( .wav isin $right($1-,4) )) {
    if ( $exists($1-)) { }
    else { %MP3.bit = N/A | %MP3.khz = N/A | %MP3.qual = N/A | goto end }
    unset %MP3.finfo | unset %MP3.fread
    %MP3.bit = N/A | %MP3.khz = N/A | %MP3.qual = N/A
    %i = 0
    :loop
    bread " $+ $1- $+ " %i 1 &MP3
    if (%i > 1500) { %MP3.bit = N/A | %MP3.khz = N/A | %MP3.qual = N/A | goto end }
    if ($bvar(&MP3,1) != 255) { inc %i 1 | goto loop }
    bread " $+ $1- $+ " %i 4 &MP3
    %i = 1
    :start
    if (%i >= 5) { unset %i }
    else { 
      %MP3.finfo = %MP3.finfo $+ $SDbvc($bvar(&MP3,%i)) 
      if (N/A isin %MP3.finfo) { %MP3.bit = N/A | %MP3.khz = N/A | %MP3.qual = N/A | goto end }
      inc %i 1 | goto start 
    }
    if ($mid(%MP3.finfo,12,2) == 11) { %MP3.Mpeg = 1.0 }
    if ($mid(%MP3.finfo,12,2) == 10) { %MP3.Mpeg = 2.0 }
    if ($mid(%MP3.finfo,12,2) == 00) { %MP3.Mpeg = 2.5 }
    if ($mid(%MP3.finfo,14,2) == 11) { %MP3.Layer = 1 }
    if ($mid(%MP3.finfo,14,2) == 10) { %MP3.Layer = 2 }
    if ($mid(%MP3.finfo,14,2) == 01) { %MP3.Layer = 3 }
    %MP3.fread = $mid(%MP3.finfo,17,4)
    if (%MP3.Layer == 1) { 
      if (%MP3.fread == 0001) { %MP3.bit = 32 }
      if (%MP3.fread == 0010) { %MP3.bit = 64 }
      if (%MP3.fread == 0011) { %MP3.bit = 96 }
      if (%MP3.fread == 0100) { %MP3.bit = 128 }
      if (%MP3.fread == 0101) { %MP3.bit = 160 }
      if (%MP3.fread == 0110) { %MP3.bit = 192 }
      if (%MP3.fread == 0111) { %MP3.bit = 224 }
      if (%MP3.fread == 1000) { %MP3.bit = 256 }
      if (%MP3.fread == 1001) { %MP3.bit = 288 }
      if (%MP3.fread == 1010) { %MP3.bit = 320 }
      if (%MP3.fread == 1011) { %MP3.bit = 352 }
      if (%MP3.fread == 1100) { %MP3.bit = 384 }
      if (%MP3.fread == 1101) { %MP3.bit = 416 }
      if (%MP3.fread == 1110) { %MP3.bit = 448 }
    }
    if (%MP3.Layer == 2) { 
      if (%MP3.fread == 0001) { %MP3.bit = 32 }
      if (%MP3.fread == 0010) { %MP3.bit = 48 }
      if (%MP3.fread == 0011) { %MP3.bit = 56 }
      if (%MP3.fread == 0100) { %MP3.bit = 64 }
      if (%MP3.fread == 0101) { %MP3.bit = 80 }
      if (%MP3.fread == 0110) { %MP3.bit = 96 }
      if (%MP3.fread == 0111) { %MP3.bit = 112 }
      if (%MP3.fread == 1000) { %MP3.bit = 128 }
      if (%MP3.fread == 1001) { %MP3.bit = 160 }
      if (%MP3.fread == 1010) { %MP3.bit = 192 }
      if (%MP3.fread == 1011) { %MP3.bit = 224 }
      if (%MP3.fread == 1100) { %MP3.bit = 256 }
      if (%MP3.fread == 1101) { %MP3.bit = 320 }
      if (%MP3.fread == 1110) { %MP3.bit = 384 }
    }
    if ((%MP3.Mpeg == 1.0) && (%MP3.Layer == 3)) { 
      if (%MP3.fread == 0001) { %MP3.bit = 32 }
      if (%MP3.fread == 0010) { %MP3.bit = 40 }
      if (%MP3.fread == 0011) { %MP3.bit = 48 }
      if (%MP3.fread == 0100) { %MP3.bit = 56 }
      if (%MP3.fread == 0101) { %MP3.bit = 64 }
      if (%MP3.fread == 0110) { %MP3.bit = 80 }
      if (%MP3.fread == 0111) { %MP3.bit = 96 }
      if (%MP3.fread == 1000) { %MP3.bit = 112 }
      if (%MP3.fread == 1001) { %MP3.bit = 128 }
      if (%MP3.fread == 1010) { %MP3.bit = 160 }
      if (%MP3.fread == 1011) { %MP3.bit = 192 }
      if (%MP3.fread == 1100) { %MP3.bit = 224 }
      if (%MP3.fread == 1101) { %MP3.bit = 256 }
      if (%MP3.fread == 1110) { %MP3.bit = 320 }
    }
    if ((%MP3.Mpeg >= 2.0) && (%MP3.Layer == 3)) { 
      if (%MP3.fread == 0001) { %MP3.bit = 8 }
      if (%MP3.fread == 0010) { %MP3.bit = 16 }
      if (%MP3.fread == 0011) { %MP3.bit = 24 }
      if (%MP3.fread == 0100) { %MP3.bit = 32 }
      if (%MP3.fread == 0101) { %MP3.bit = 40 }
      if (%MP3.fread == 0110) { %MP3.bit = 48 }
      if (%MP3.fread == 0111) { %MP3.bit = 56 }
      if (%MP3.fread == 1000) { %MP3.bit = 64 }
      if (%MP3.fread == 1001) { %MP3.bit = 80 }
      if (%MP3.fread == 1010) { %MP3.bit = 96 }
      if (%MP3.fread == 1011) { %MP3.bit = 112 }
      if (%MP3.fread == 1100) { %MP3.bit = 128 }
      if (%MP3.fread == 1101) { %MP3.bit = 144 }
      if (%MP3.fread == 1110) { %MP3.bit = 160 }
    }
    %MP3.fread = $mid(%MP3.finfo,21,2)
    if (%MP3.Mpeg == 1.0) { 
      if (%MP3.fread == 00) { %MP3.khz = 44.1 }
      if (%MP3.fread == 01) { %MP3.khz = 48.0 }
      if (%MP3.fread == 10) { %MP3.khz = 32.0 }
    }
    if (%MP3.Mpeg == 2.0) { 
      if (%MP3.fread == 00) { %MP3.khz = 22.1 }
      if (%MP3.fread == 01) { %MP3.khz = 24.0 }
      if (%MP3.fread == 10) { %MP3.khz = 16.0 }
    }
    if (%MP3.Mpeg == 2.5) { 
      if (%MP3.fread == 00) { %MP3.khz = 11.0 }
      if (%MP3.fread == 01) { %MP3.khz = 12.0 }
      if (%MP3.fread == 10) { %MP3.khz = 8.0 }
    }
    %MP3.fread = $mid(%mp3.finfo,25,2)
    if (%MP3.fread == 00) { %MP3.qual = Stereo }
    if (%MP3.fread == 01) { %MP3.qual = Joint Stereo }
    if (%MP3.fread == 10) { %MP3.qual = Stereo }
    if (%MP3.fread == 11) { %MP3.qual = Mono }
    :end 
    if (%MP3.bit != N/A) { 
      set %MP3.Time $int($calc($file($1-).size / (%MP3.bit * 125))) 
    }
    else { 
      set %MP3.Time N/A
    }
    set %mp3size $file($1-).size
    unset %mp3.Mpeg
    unset %mp3.Layer
    unset %MP3.bit
    unset %MP3.khz
    unset %MP3.qual
    unset %MP3.Time
    unset %mp3.finfo
    unset %mp3.bvc.nr
    unset %mp3.bvc.2dt
    unset %mp3.bvc.rslt
    unset %MP3.fread
    return %mp3size
  }
  else {
    return $file($1-) .size
  }
}
